Exemplo n.º 1
0
 /**
  * The configured SigType to expect on read-in
  *
  * @since 0.9.16
  */
 public static SigType getSigTypeConfig(RouterContext ctx) {
   SigType cstype = DEFAULT_SIGTYPE;
   String sstype = ctx.getProperty(PROP_ROUTER_SIGTYPE);
   if (sstype != null) {
     SigType ntype = SigType.parseSigType(sstype);
     if (ntype != null) cstype = ntype;
   }
   // fallback?
   if (cstype != SigType.DSA_SHA1 && !cstype.isAvailable()) cstype = SigType.DSA_SHA1;
   return cstype;
 }
Exemplo n.º 2
0
 /**
  * @param opts may be null
  * @since 0.9.21 copied from I2PSocketManagerFactory
  */
 private SigType getSigType(Properties opts) {
   if (opts != null) {
     String st = opts.getProperty(I2PClient.PROP_SIGTYPE);
     if (st != null) {
       SigType rv = SigType.parseSigType(st);
       if (rv != null && rv.isAvailable()) return rv;
       if (rv != null) st = rv.toString();
       _log.logAlways(
           Log.WARN, "Unsupported sig type " + st + ", reverting to " + I2PClient.DEFAULT_SIGTYPE);
       // TODO throw instead?
     }
   }
   return I2PClient.DEFAULT_SIGTYPE;
 }
Exemplo n.º 3
0
  /* Parse and execute a DEST message*/
  protected boolean execDestMessage(String opcode, Properties props) {

    if (opcode.equals("GENERATE")) {
      String sigTypeStr = props.getProperty("SIGNATURE_TYPE");
      SigType sigType;
      if (sigTypeStr != null) {
        sigType = SigType.parseSigType(sigTypeStr);
        if (sigType == null) {
          writeString(
              "DEST REPLY RESULT=I2P_ERROR MESSAGE=\"SIGNATURE_TYPE "
                  + sigTypeStr
                  + " unsupported\"\n");
          return false;
        }
      } else {
        sigType = SigType.DSA_SHA1;
      }

      ByteArrayOutputStream priv = new ByteArrayOutputStream(663);
      ByteArrayOutputStream pub = new ByteArrayOutputStream(387);

      SAMUtils.genRandomKey(priv, pub, sigType);
      return writeString(
          "DEST REPLY"
              + " PUB="
              + Base64.encode(pub.toByteArray())
              + " PRIV="
              + Base64.encode(priv.toByteArray())
              + "\n");
    } else {
      writeString("DEST REPLY RESULT=I2P_ERROR MESSAGE=\"DEST GENERATE required\"");
      if (_log.shouldLog(Log.DEBUG))
        _log.debug("Unrecognized DEST message opcode: \"" + opcode + "\"");
      return false;
    }
  }
Exemplo n.º 4
0
 static {
   for (SigType type : SigType.values()) {
     BY_CODE.put(Integer.valueOf(type.getCode()), type);
   }
 }