Exemplo n.º 1
0
  /**
   * Endorse the proof
   *
   * @param aStampContext current context
   * @param aProof proof
   * @return endorsed proof
   * @throws NoSuchAlgorithmException
   * @throws BadPaddingException
   * @throws IllegalBlockSizeException
   * @throws NoSuchPaddingException
   * @throws InvalidKeyException
   */
  private static byte[] endorseP(WitnessContext aStampContext, byte aProof[]) {

    // Sign on the proof first
    byte[] sig = {};
    try {
      sig = CryptoUtil.signDSA(aStampContext.getPriDSASelf(), aProof);
    } catch (InvalidKeyException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (SignatureException e) {
      e.printStackTrace();
    }

    // Include own ID in EP
    byte[] wID = aStampContext.getPubDSASelf().getEncoded();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(wID);
    array.add(aProof);
    array.add(sig);

    byte[] epContent = MessageUtil.compileMessages(array);

    // Encrypt epContent with an AES key first
    SecretKey aesKey = null;
    byte[] epEncrypted = {};
    byte[] keyEncrypted = {};
    try {
      aesKey = CryptoUtil.generateAESKey(128);
      epEncrypted = CryptoUtil.encryptAES(aesKey, epContent);
      keyEncrypted = CryptoUtil.encryptRSA(aStampContext.getPubRSACA(), aesKey.getEncoded());
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    } catch (InvalidKeyException e) {
      e.printStackTrace();
    } catch (NoSuchPaddingException e) {
      e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
      e.printStackTrace();
    } catch (BadPaddingException e) {
      e.printStackTrace();
    }

    ArrayList<byte[]> arrayOut = new ArrayList<byte[]>();
    arrayOut.add(epEncrypted);
    arrayOut.add(keyEncrypted);

    return MessageUtil.compileMessages(arrayOut);
  }
Exemplo n.º 2
0
  /**
   * Create EP message body EP = r_w1|E^(K_ca)(ID_W|P|E^(K_W)(Hash(P)))
   *
   * @param aStampContext current context
   * @return EP message body
   */
  public static byte[] createEP(WitnessContext aStampContext) {
    byte proof[] = createP(aStampContext);
    byte eproof[] = endorseP(aStampContext, proof);
    byte randomW[] = aStampContext.getEPRandomW().toByteArray();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(eproof);
    array.add(randomW);

    return MessageUtil.compileMessages(array);
  }
Exemplo n.º 3
0
  /**
   * Create Preq message body Preq = Comm(ID_P, r_P)|T|L_1
   *
   * @param aStampContext current context
   * @param aLocLevel desired location level (0 usually)
   * @return Preq message
   */
  public static byte[] createPreq(ProverContext aStampContext) {
    byte commID[] = aStampContext.getCommittedID();
    byte time[] = ByteBuffer.allocate(8).putLong(ProverContext.getTime()).array();
    /* TODO: check if aLocLevel is valid */
    byte location[] = aStampContext.getLocation().toString().getBytes();

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(commID);
    array.add(time);
    array.add(location);

    return MessageUtil.compileMessages(array);
  }
Exemplo n.º 4
0
  /**
   * Create a proof P = Comm(ID_p, r_p)|C_k|C_e|STPR
   *
   * @param aStampContext current context
   * @return proof
   */
  private static byte[] createP(WitnessContext aStampContext) {
    byte commID[] = aStampContext.getRemoteCommittedID();
    byte z[] = aStampContext.getRemoteZ().toByteArray();

    byte location[] = aStampContext.getRemoteLocation();
    byte time[] = aStampContext.getRemoteTime();
    byte stpr[] = createSTPR(aStampContext, location, time);

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(commID);
    array.add(z);
    array.add(stpr);

    return MessageUtil.compileMessages(array);
  }
Exemplo n.º 5
0
  /**
   * Create DB ready message body
   *
   * @return DB ready message
   */
  public static byte[] createCeCk(ProverContext aStampContext) {

    BigInteger e = aStampContext.getE();
    BigInteger k = aStampContext.getK();
    BigInteger p = aStampContext.getPubDSASelf().getParams().getP();
    BigInteger g = aStampContext.getPubDSASelf().getParams().getG();
    BigInteger h = aStampContext.getH();
    BigInteger v = aStampContext.getV();

    ArrayList<byte[]> ces = CryptoUtil.getBitCommitments(g, p, h, v, e);
    ArrayList<byte[]> cks = CryptoUtil.getBitCommitments(g, p, h, v, k);

    byte[] cesBytes = MessageUtil.createMessageFromArray(ces);
    byte[] cksBytes = MessageUtil.createMessageFromArray(cks);

    ArrayList<byte[]> array = new ArrayList<byte[]>();
    array.add(cesBytes);
    array.add(cksBytes);

    return MessageUtil.compileMessages(array);
  }