Esempio n. 1
0
  @Test
  public void testConstruction() throws EncodingException {
    // Debug: This should be a Certificate.
    Data certificate = new Data();
    certificate.wireDecode(new Blob(CERT, false));

    // TODO: Finish tests.
  }
Esempio n. 2
0
  /**
   * Wire encode the Data object, digest it and set its SignatureInfo to a DigestSha256.
   *
   * @param data The Data object to be signed. This updates its signature and wireEncoding.
   * @param wireFormat The WireFormat for calling encodeData.
   */
  public final void signWithSha256(Data data, WireFormat wireFormat) {
    data.setSignature(new DigestSha256Signature());

    // Encode once to get the signed portion.
    SignedBlob encoding = data.wireEncode(wireFormat);

    // Digest and set the signature.
    byte[] signedPortionDigest = Common.digestSha256(encoding.signedBuf());
    data.getSignature().setSignature(new Blob(signedPortionDigest, false));

    // Encode again to include the signature.
    data.wireEncode(wireFormat);
  }
Esempio n. 3
0
  /**
   * Create an IdentityCertificate from the content in the data packet.
   *
   * @param data The data packet with the content to decode.
   */
  public IdentityCertificate(Data data) throws DerDecodingException {
    super(data);

    if (!isCorrectName(data.getName()))
      throw new SecurityException("Wrong Identity Certificate Name!");

    setPublicKeyName();
  }
Esempio n. 4
0
  @Test
  public void testExpressingAnInterestAfterConfiguration()
      throws IOException, EncodingException, InterruptedException {
    // add response (before face is connected)
    Data response = new Data(new Name("/test/with/responses"));
    response.setContent(new Blob("..."));
    face.receive(response);

    // make request
    expressInterest("/test/with/responses");

    run(20);

    assertNotNull(recvData);
    assertEquals(isTimeout, false);
    assertEquals(recvData.getName().toString(), "/test/with/responses");
    assertEquals(recvData.getContent().buf(), new Blob("...").buf());
  }
Esempio n. 5
0
  /**
   * Sign data packet based on the certificate name.
   *
   * @param data The Data object to sign and update its signature.
   * @param certificateName The Name identifying the certificate which identifies the signing key.
   * @param wireFormat The WireFormat for calling encodeData.
   */
  public final void signByCertificate(Data data, Name certificateName, WireFormat wireFormat)
      throws SecurityException {
    DigestAlgorithm[] digestAlgorithm = new DigestAlgorithm[1];
    Signature signature = makeSignatureByCertificate(certificateName, digestAlgorithm);

    data.setSignature(signature);
    // Encode once to get the signed portion.
    SignedBlob encoding = data.wireEncode(wireFormat);

    data.getSignature()
        .setSignature(
            privateKeyStorage_.sign(
                encoding.signedBuf(),
                IdentityCertificate.certificateNameToPublicKeyName(certificateName),
                digestAlgorithm[0]));

    // Encode again to include the signature.
    data.wireEncode(wireFormat);
  }