Exemplo n.º 1
0
 void checkConsistency() throws IOException {
   for (CmdLineArgument cla1 : list) {
     if (cla1.found) {
       // Now check for mutual exclusion....
       for (CmdLineArgument cla2 : list) {
         if (cla1.group == cla2.mutually_exclusive_group && cla2.found) {
           bad(
               "Command '-"
                   + cla1.command
                   + "' cannot be combined with '-"
                   + cla2.command
                   + "'");
         }
       }
     } else if (cla1.frequency == CmdFrequency.SINGLE
         || cla1.frequency == CmdFrequency.MULTIPLE) {
       String other = "";
       boolean bad = true;
       for (CmdLineArgument cla2 : list) {
         if (cla1.group == cla2.mutually_exclusive_group) {
           if (cla2.found) {
             bad = false;
             break;
           }
           if (cla2.frequency == CmdFrequency.SINGLE
               || cla2.frequency == CmdFrequency.MULTIPLE) {
             other = " or -" + cla2.command;
             for (CmdLineArgument cla3 : list) {
               if (cla3.found && cla3.group == cla1.group) {
                 other = "";
                 break;
               }
             }
           }
         }
       }
       if (bad) {
         bad("Missing command: -" + cla1.command + other);
       }
     } else if (cla1.frequency == CmdFrequency.OPTIONAL && cla1.defaultvalue != null) {
       boolean do_it = true;
       for (CmdLineArgument cla2 : list) {
         if (cla1.group == cla2.mutually_exclusive_group) {
           if (cla2.found) {
             do_it = false;
             break;
           }
         }
       }
       if (do_it) {
         cla1.argvalue.add(cla1.defaultvalue);
         cla1.found = true;
       }
     }
   }
 }
Exemplo n.º 2
0
 void setMutuallyExclusive(CmdLineArgumentGroup group1, CmdLineArgumentGroup group2) {
   for (CmdLineArgument cla1 : list) {
     if (cla1.group == group1) {
       for (CmdLineArgument cla2 : list) {
         if (cla2.group == group2) {
           cla1.mutually_exclusive_group = group2;
           cla2.mutually_exclusive_group = group1;
         }
       }
     }
   }
 }
Exemplo n.º 3
0
 CmdLineArgument get(String argument) throws IOException {
   for (CmdLineArgument cla : list) {
     if (cla.command.equals(argument.substring(1))) {
       if (cla.found
           && (cla.frequency == CmdFrequency.OPTIONAL || cla.frequency == CmdFrequency.SINGLE)) {
         bad("Duplicate command: " + argument);
       }
       cla.found = true;
       return cla;
     }
   }
   bad("No such command: " + argument);
   return null; // For the parser only
 }
Exemplo n.º 4
0
 void initiateProviderKeyStore(Provider provider) throws Exception {
   String prov = null;
   for (Provider.Service ps : provider.getServices()) {
     if (ps.getType().equals("KeyStore")) {
       prov = ps.getAlgorithm();
     }
   }
   Security.addProvider(provider);
   KeyStore ks = KeyStore.getInstance(prov, provider);
   ks.load(
       CMD_keystore.found ? new FileInputStream(CMD_keystore.getString()) : null,
       CMD_keypass.found ? CMD_keypass.getString().toCharArray() : null);
   wrap.setKeyStore(ks, CMD_keypass.getString());
   CMD_keystore.found = false;
 }
Exemplo n.º 5
0
    void execute(String argv[]) throws Exception {
      decodeCommandLine(argv);

      if (CMD_proxyhost.found != CMD_proxyport.found) {
        bad(
            "Missing command: -"
                + (CMD_proxyhost.found ? CMD_proxyport.command : CMD_proxyhost.command));
      }

      wrap.setInteractiveMode(true);

      if (CMD_user_id.found || CMD_password.found) {
        if (CMD_user_id.found != CMD_password.found) {
          bad(
              "Missing command: -"
                  + (CMD_user_id.found ? CMD_password.command : CMD_user_id.command));
        }
        wrap.setUserIDPassword(CMD_user_id.getString(), CMD_password.getString());
      }

      if (CMD_proxyhost.found) {
        wrap.setProxy(CMD_proxyhost.getString(), CMD_proxyport.getInteger());
      }

      if (CMD_timeout.found) {
        wrap.setTimeout(CMD_timeout.getInteger());
      }

      if (CMD_follow_redirs.found) {
        wrap.setFollowRedirects(true);
      }

      if (CMD_badnames_ok.found) {
        wrap.allowDiffHostNames(true);
      }

      if (CMD_invalid_ok.found) {
        wrap.allowInvalidCert(true);
      }

      if (CMD_setheader.found) {
        for (String value : CMD_setheader.argvalue) {
          value = value.trim();
          int i = value.indexOf(':');
          if (i <= 0 || i == value.length() - 1) {
            bad("Misformed header argument: " + value);
          }
          wrap.setHeader(value.substring(0, i), value.substring(i + 1));
        }
      }

      if (CMD_mime_type.found) {
        wrap.setHeader("Content-Type", CMD_mime_type.getString());
      }

      if (CMD_p11lib.found) {
        String p11wrapper = "sun.security.pkcs11.SunPKCS11";
        if (CMD_addprovider.found) {
          p11wrapper = CMD_addprovider.getString();
          CMD_addprovider.found = false;
        }
        if (CMD_p11slot.found) {
          String slot = CMD_p11slot.getString();
          String slot_label = "slot";
          if (slot.charAt(0) == 'i') {
            slot_label = "slotListIndex";
            slot = slot.substring(1);
          }
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintWriter pw = new PrintWriter(baos);
          pw.println(
              "name = " + new File(CMD_p11lib.getString()).getName() + "-" + slot_label + slot);
          pw.println("library = " + CMD_p11lib.getString());
          pw.println(slot_label + " = " + slot);
          pw.flush();
          pw.close();
          initiateProviderKeyStore(
              (Provider)
                  Class.forName(p11wrapper)
                      .getConstructor(InputStream.class)
                      .newInstance(new ByteArrayInputStream(baos.toByteArray())));
        } else {
          initiateProviderKeyStore(
              (Provider)
                  Class.forName(p11wrapper)
                      .getConstructor(String.class)
                      .newInstance(CMD_p11lib.getString()));
        }
      }

      if (CMD_addprovider.found) {
        initiateProviderKeyStore(
            CMD_provider_arg.found
                ? (Provider)
                    Class.forName(CMD_addprovider.getString())
                        .getConstructor(String.class)
                        .newInstance(CMD_provider_arg.getString())
                : (Provider) Class.forName(CMD_addprovider.getString()).newInstance());
      }

      if (CMD_truststore.found) {
        wrap.setTrustStore(CMD_truststore.getString(), CMD_storepass.getString());
      }

      if (CMD_keystore.found) {
        wrap.setKeyStore(CMD_keystore.getString(), CMD_keypass.getString());
      }

      if (CMD_keyalias.found) {
        wrap.setKeyAlias(CMD_keyalias.getString());
      }

      if (CMD_get_oper.found) {
        wrap.makeGetRequest(CMD_get_oper.getString());
      } else {
        wrap.makePostRequest(
            CMD_post_oper.getString(), ArrayUtil.readFile(CMD_data_file.getString()));
      }

      if (CMD_dump_certs.found) {
        System.out.println(
            "\nCertificate:\n" + new CertificateInfo(wrap.getServerCertificate()).toString());
      }

      if (CMD_dump_headers.found) {
        System.out.println(
            "\nHeaders:\n" + wrap.getResponseCode() + " " + wrap.getResponseMessage());
        LinkedHashMap<String, Vector<String>> headers = wrap.getHeaders();
        for (String key : headers.keySet()) {
          for (String value : headers.get(key)) {
            System.out.println(key + ": " + value);
          }
        }
      }

      if (CMD_dump_data.found) {
        System.out.println("\nData:\n" + wrap.getDataUTF8());
      }

      if (CMD_store_data.found) {
        ArrayUtil.writeFile(CMD_store_data.getString(), wrap.getData());
      }
    }