Package ca.carleton.gcrc.security.ber

Examples of ca.carleton.gcrc.security.ber.BerObject


public class TokenDecoder {

  public Token decode(byte[] encodedToken) throws Exception {
    try {
      BerObject outerObj = BerDecoder.decode(encodedToken);
     
      if( false == outerObj.isTypeConstructed()
       || false == (outerObj instanceof BerConstructed) ){
        throw new Exception("Object is not constructed.");
      }
      BerConstructed outer = (BerConstructed)outerObj;
View Full Code Here


  static public BerObject decode(byte[] encoded) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
    BerInputStream berIs = new BerInputStream(bais);
    berIs.pushLimit(encoded.length);
   
    BerObject obj = decode(berIs);
   
    berIs.popLimit();
   
    return obj;
  }
View Full Code Here

 
  static public BerObject decode(BerInputStream is, BerImplementation impl) throws Exception {
    BerTag tag = BerTagEncoder.decodeTag(is);
    int length = BerLengthEncoder.decodeLength(is);
   
    BerObject result = null;
    if( tag.isConstructed() ) {
      BerConstructed constructed = impl.createConstructed(tag.getTypeClass(), tag.getType());
      result = constructed;
     
      is.pushLimit(length);
     
      while(is.getCurrentLimit() > 0) {
        BerObject child = decode(is);
        constructed.add(child);
      }
     
      is.popLimit();
    } else {
View Full Code Here

  private static int encodeConstructed(BerConstructed contructedObj, Stack<ByteBuffer> components) throws Exception {
    int totalLen = 0;
   
    // Starting from the last object, push unto stack
    for(int loop=contructedObj.size()-1; loop>=0; --loop) {
      BerObject thisObj = contructedObj.get(loop);
      int thisLen = encode(thisObj, components);
      totalLen = totalLen + thisLen;
    }
   
    byte[] len = BerLengthEncoder.encodeLength(totalLen);
View Full Code Here

  }

  static public Token decryptToken(byte[] productionKey, byte[] encryptedToken) throws Exception {
   
    try {
      BerObject outerObj = BerDecoder.decode(encryptedToken);
     
      if( false == outerObj.isTypeConstructed()
       || false == (outerObj instanceof BerConstructed) ){
        throw new Exception("Object is not constructed.");
      }
      if( Token.APPLICATION_TYPE_ENCRYPTED != outerObj.getType() ){
        throw new Exception("Unexpected type.");
      }
      BerConstructed outer = (BerConstructed)outerObj;
     
      // Check that we have enough members
      if( outer.size() < 2 ){
        throw new Exception("Not enough components.");
      }
     
      // Get context
      BerObject contextObj = outer.get(0);
      if( false == (contextObj instanceof BerBytes) ){
        throw new Exception("Invalid context.");
      }
      byte[] context = ((BerBytes)contextObj).getValue();
     
      // Get encrypted payload
      BerObject encryptedObj = outer.get(1);
      if( false == (encryptedObj instanceof BerBytes) ){
        throw new Exception("Invalid encrypted payload.");
      }
      byte[] encryptedPayload = ((BerBytes)encryptedObj).getValue();
     
View Full Code Here

     
      PasswordRecoveryToken token = new PasswordRecoveryToken();
     
      // Get email address
      {
        BerObject emailObj = outer.get(0);
        if( false == (emailObj instanceof BerString) ){
          throw new Exception("Invalid email address");
        }
        String email = ((BerString)emailObj).getValue();
        token.setEmailAddress(email);
      }
     
      // Get expiry
      {
        BerObject expiryObj = outer.get(1);
        if( false == (expiryObj instanceof BerInteger) ){
          throw new Exception("Invalid expiry date");
        }
        long expiry = ((BerInteger)expiryObj).getValue();
        Date expiryDate = new Date(expiry);
        token.setExpiry(expiryDate);
      }
     
      // Get version
      {
        BerObject versionObj = outer.get(2);
        if( false == (versionObj instanceof BerString) ){
          throw new Exception("Invalid version");
        }
        String version = ((BerString)versionObj).getValue();
        token.setVersion(version);
View Full Code Here

     
      CreationToken token = new CreationToken();
     
      // Get email address
      {
        BerObject emailObj = outer.get(0);
        if( false == (emailObj instanceof BerString) ){
          throw new Exception("Invalid email address");
        }
        String email = ((BerString)emailObj).getValue();
        token.setEmailAddress(email);
      }
     
      // Get expiry
      {
        BerObject expiryObj = outer.get(1);
        if( false == (expiryObj instanceof BerInteger) ){
          throw new Exception("Invalid expiry date");
        }
        long expiry = ((BerInteger)expiryObj).getValue();
        Date expiryDate = new Date(expiry);
View Full Code Here

public class TokenDecoder {

  public Token decode(byte[] encodedToken) throws Exception {
    try {
      BerObject outerObj = BerDecoder.decode(encodedToken);
     
      if( false == outerObj.isTypeConstructed()
       || false == (outerObj instanceof BerConstructed) ){
        throw new Exception("Object is not constructed.");
      }
      BerConstructed outer = (BerConstructed)outerObj;
View Full Code Here

TOP

Related Classes of ca.carleton.gcrc.security.ber.BerObject

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.