Changeset 33708

Show
Ignore:
Timestamp:
20.11.2019 11:30:47 (2 weeks ago)
Author:
davidb
Message:

Changed code so api key can be in separate file, and passed in on the command-line to the Java code

Location:
gs2-extensions/malware-checker/trunk/java
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/malware-checker/trunk/java/AddComment.sh

    r33665 r33708  
    11#!/bin/bash 
    22 
    3 java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.AddComment $* 
     3if [ -f virustotal-key.txt ] ; then 
     4    apikey=`cat virustotal-key.txt` 
     5fi 
     6 
     7java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.AddComment $apikey $* 
    48 
    59         
  • gs2-extensions/malware-checker/trunk/java/GetFileScanReport.sh

    r33665 r33708  
    11#!/bin/bash 
    22 
    3 java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.GetFileScanReport $* 
     3if [ -f virustotal-key.txt ] ; then 
     4    apikey=`cat virustotal-key.txt` 
     5fi 
     6 
     7java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.GetFileScanReport $apikey $* 
    48 
    59         
  • gs2-extensions/malware-checker/trunk/java/ScanFile.sh

    r33665 r33708  
    11#!/bin/bash 
    22 
    3 java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.ScanFile $* 
     3if [ -f virustotal-key.txt ] ; then 
     4    apikey=`cat virustotal-key.txt` 
     5fi 
     6 
     7java -cp target/malware-checker-1.0-SNAPSHOT-jar-with-dependencies.jar org.greenstone.virustotal.ScanFile $apikey $* 
    48 
    59         
  • gs2-extensions/malware-checker/trunk/java/src/main/java/org/greenstone/virustotal/AddComment.java

    r33664 r33708  
    1010 
    1111public class AddComment { 
     12 
     13    public static void printUsage() { 
     14    System.err.println("Usage: AddComment api-key resource-id comment"); 
     15    System.exit(1); 
     16    } 
     17     
    1218    public static void main(String[] args) { 
     19    String apiKey = null; 
     20    String resourceID = null; 
     21    String comment = null;   
    1322 
    1423        try { 
    15             VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("09311639ef4193fc22faa35d493a5bf12dc44844a55f03812e40bd1a16fd7b6f"); 
     24 
     25        if (args.length==3) { 
     26        apiKey = args[0]; 
     27        resourceID = args[1]; 
     28        comment = args[2]; 
     29        } 
     30        else { 
     31        printUsage(); 
     32        } 
     33 
     34             
     35            VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey(apiKey); 
    1636            VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl(); 
    17  
    18             String resourceID = null; 
    19         String comment = null;   
    20         resourceID = args[0]; 
    21             comment = args[1]; 
    2237     
    2338            GeneralResponse gRespo = virusTotalRef.makeAComment(resourceID, comment); 
  • gs2-extensions/malware-checker/trunk/java/src/main/java/org/greenstone/virustotal/GetFileScanReport.java

    r33664 r33708  
    1818public class GetFileScanReport { 
    1919     
     20    public static void printUsage() { 
     21    System.err.println("Usage: GetFileScanReport api-key resource-id"); 
     22    System.exit(1); 
     23    } 
    2024 
    2125    public static void main(String[] args) { 
    2226        try { 
    23             VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("09311639ef4193fc22faa35d493a5bf12dc44844a55f03812e40bd1a16fd7b6f"); 
     27        String apiKey = null; 
     28        String resourceID = null; 
     29         
     30        if (args.length==2) { 
     31        apiKey = args[0]; 
     32        resourceID = args[1]; 
     33        } 
     34        else { 
     35        printUsage(); 
     36        } 
     37         
     38            VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey(apiKey); 
    2439            VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl(); 
    2540     
    26         String resourceID = null; 
    27         resourceID = args[0]; 
    2841            FileScanReport report = virusTotalRef.getScanReport(resourceID); 
    2942 
  • gs2-extensions/malware-checker/trunk/java/src/main/java/org/greenstone/virustotal/ScanFile.java

    r33664 r33708  
    1515public class ScanFile { 
    1616    public static void printUsage(){ 
    17         System.err.println("Usage: ScanFile [all] file"); 
     17        System.err.println("Usage: ScanFile [-all] api-key file"); 
    1818        System.exit(1); 
    1919    } 
    2020 
    2121    public static void main(String[] args) { 
     22    String apiKey = null; 
    2223    String inputFileName = null; 
     24     
    2325    boolean printall=false; 
    24     if (args.length<1 || args.length>2){ 
     26    if (args.length<1 || args.length>3){ 
    2527        printUsage(); 
    2628 
    2729    } 
    28     else if(args.length==2){ 
    29         if(args[0].equals("all")){ 
    30             inputFileName = args[1]; 
     30    else if(args.length==3){ 
     31        if(args[0].equals("-all")){ 
     32            apiKey = args[1]; 
     33            inputFileName = args[2]; 
    3134            printall=true; 
    3235        } 
     
    3639             
    3740    } 
    38      
    39     else{ 
    40         inputFileName = args[0]; 
     41    else if(args.length==2){ 
     42        apiKey = args[0]; 
     43        inputFileName = args[1]; 
     44    } 
     45    else { 
     46        printUsage(); 
    4147    } 
    4248 
    4349    try { 
    4450     
    45             VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("09311639ef4193fc22faa35d493a5bf12dc44844a55f03812e40bd1a16fd7b6f"); 
     51            VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey(apiKey); 
     52         
    4653            VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl(); 
    4754