Package org.apache.abdera.security.util

Examples of org.apache.abdera.security.util.DHContext


    // There are two participants in the session, A and B
    // Each has their own DHContext. A creates their context and
    // sends the request key parameters to B.  B uses those parameters
    // to create their context, the returns it's public key
    // back to A.
    DHContext context_a = new DHContext();
    DHContext context_b = new DHContext(context_a.getRequestString());
    context_a.setPublicKey(context_b.getResponseString());

    // Prepare the encryption options
    Encryption enc = absec.getEncryption();
   
    // Encrypt the document using A's DHContext
    EncryptionOptions options = context_a.getEncryptionOptions(enc);
    Document enc_doc = enc.encrypt(entry.getDocument(), options);

    enc_doc.writeTo(System.out);
   
    System.out.println("\n\n");
   
    // Decrypt the document using B's DHContext
    options = context_b.getEncryptionOptions(enc);
    Document<Entry> entry_doc = enc.decrypt(enc_doc, options);

    entry_doc.writeTo(System.out);
   
  }
View Full Code Here


      ResponseContext response,
      Encryption enc,
      Object arg) {
    EncryptionOptions options = null;
    try {
      DHContext context = (DHContext) arg;
      options = context.getEncryptionOptions(enc);
      returnPublicKey(response,context);
    } catch (Exception e) {}
    return options;
   
  }
View Full Code Here

 
  public ResponseContext filter(
    RequestContext request,
    FilterChain chain) {
      ResponseContext response = super.filter(request,chain);
      DHContext context = getDHContext(request);
      response.setHeader(
        Constants.CONTENT_ENCRYPTED,
        context.getResponseString());
      return response;
  }
View Full Code Here

 
  private DHContext getDHContext(RequestContext request) {
    try {
      String dh_req = request.getHeader(Constants.ACCEPT_ENCRYPTION);
      if (dh_req == null || dh_req.length() == 0) return null;
      return new DHContext(dh_req);
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

      // the header will specify all the information the client needs to construct
      // it's own DH context and encrypt the request
      if ("GET".equalsIgnoreCase(method) ||
          "HEAD".equalsIgnoreCase(method) ||
          "OPTIONS".equalsIgnoreCase(method)) {
        DHContext context =
          (DHContext) request.getAttribute(
            Scope.SESSION,
            "dhcontext");
        if (context == null) {
          context = new DHContext();
          request.setAttribute(Scope.SESSION, "dhcontext", context);
        }
        response.setHeader(
          Constants.ACCEPT_ENCRYPTION,
          context.getRequestString());
      }
      return response;
  }
View Full Code Here

      }
      return response;
  }

  protected Object initArg(RequestContext request) {
    DHContext context =
      (DHContext) request.getAttribute(
        Scope.SESSION,
        "dhcontext");
    String dh = request.getHeader(Constants.CONTENT_ENCRYPTED);
    if (context != null && dh != null && dh.length() > 0) {
      try {
        context.setPublicKey(dh);
      } catch (Exception e) {}
    }
    return context;
  }
View Full Code Here

        // There are two participants in the session, A and B
        // Each has their own DHContext. A creates their context and
        // sends the request key parameters to B. B uses those parameters
        // to create their context, the returns it's public key
        // back to A.
        DHContext context_a = new DHContext();
        DHContext context_b = new DHContext(context_a.getRequestString());
        context_a.setPublicKey(context_b.getResponseString());

        // Prepare the encryption options
        Encryption enc = absec.getEncryption();

        // Encrypt the document using A's DHContext
        EncryptionOptions options = context_a.getEncryptionOptions(enc);
        Document enc_doc = enc.encrypt(entry.getDocument(), options);

        enc_doc.writeTo(System.out);

        System.out.println("\n\n");

        // Decrypt the document using B's DHContext
        options = context_b.getEncryptionOptions(enc);
        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);

        entry_doc.writeTo(System.out);

    }
View Full Code Here

                                                      ResponseContext response,
                                                      Encryption enc,
                                                      Object arg) {
        EncryptionOptions options = null;
        try {
            DHContext context = (DHContext)arg;
            options = context.getEncryptionOptions(enc);
            returnPublicKey(response, context);
        } catch (Exception e) {
        }
        return options;
View Full Code Here

    }

    public ResponseContext filter(RequestContext request, FilterChain chain) {
        ResponseContext response = super.filter(request, chain);
        DHContext context = getDHContext(request);
        response.setHeader(Constants.CONTENT_ENCRYPTED, context.getResponseString());
        return response;
    }
View Full Code Here

    private DHContext getDHContext(RequestContext request) {
        try {
            String dh_req = request.getHeader(Constants.ACCEPT_ENCRYPTION);
            if (dh_req == null || dh_req.length() == 0)
                return null;
            return new DHContext(dh_req);
        } catch (Exception e) {
            return null;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.security.util.DHContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.