예제 #1
0
 /**
  * Return the DER encoded form of the certificate pair.
  *
  * @return The encoded form of the certificate pair.
  * @throws CerticateEncodingException If an encoding exception occurs.
  */
 public byte[] getEncoded() throws CertificateEncodingException {
   try {
     if (encoded == null) {
       DerOutputStream tmp = new DerOutputStream();
       emit(tmp);
       encoded = tmp.toByteArray();
     }
   } catch (IOException ex) {
     throw new CertificateEncodingException(ex.toString());
   }
   return encoded;
 }
예제 #2
0
 /** Construct a key from its components. Used by the KeyFactory. */
 ECPrivateKeyImpl(BigInteger s, ECParameterSpec params) throws InvalidKeyException {
   this.s = s;
   this.params = params;
   // generate the encoding
   algid = new AlgorithmId(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(1); // version 1
     byte[] privBytes = ECUtil.trimZeroes(s.toByteArray());
     out.putOctetString(privBytes);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }
예제 #3
0
 /**
  * Encodes a Checksum object. <xmp> Checksum ::= SEQUENCE { cksumtype [0] Int32, checksum [1]
  * OCTET STRING } </xmp>
  *
  * <p>This definition reflects the Network Working Group RFC 4120 specification available at <a
  * href="http://www.ietf.org/rfc/rfc4120.txt">http://www.ietf.org/rfc/rfc4120.txt</a>.
  *
  * @return byte array of enocded Checksum.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(cksumType));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   temp.putOctetString(checksum);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
예제 #4
0
  /**
   * Returns a flat name representation for this object. The name format is defined in RFC 2743:
   *
   * <pre>
   * Length           Name          Description
   * 2               TOK_ID          Token Identifier
   *                                 For exported name objects, this
   *                                 must be hex 04 01.
   * 2               MECH_OID_LEN    Length of the Mechanism OID
   * MECH_OID_LEN    MECH_OID        Mechanism OID, in DER
   * 4               NAME_LEN        Length of name
   * NAME_LEN        NAME            Exported name; format defined in
   *                                 applicable mechanism draft.
   * </pre>
   *
   * Note that it is not required to canonicalize a name before calling export(). i.e., the name
   * need not be an MN. If it is not an MN, an implementation defined algorithm can be used for
   * choosing the mechanism which should export this name.
   *
   * @return the flat name representation for this object
   * @exception GSSException with major codes NAME_NOT_MN, BAD_NAME, BAD_NAME, FAILURE.
   */
  public byte[] export() throws GSSException {

    if (mechElement == null) {
      /* Use default mech */
      mechElement = getElement(ProviderList.DEFAULT_MECH_OID);
    }

    byte[] mechPortion = mechElement.export();
    byte[] oidBytes = null;
    ObjectIdentifier oid = null;

    try {
      oid = new ObjectIdentifier(mechElement.getMechanism().toString());
    } catch (IOException e) {
      throw new GSSExceptionImpl(GSSException.FAILURE, "Invalid OID String ");
    }
    DerOutputStream dout = new DerOutputStream();
    try {
      dout.putOID(oid);
    } catch (IOException e) {
      throw new GSSExceptionImpl(GSSException.FAILURE, "Could not ASN.1 Encode " + oid.toString());
    }
    oidBytes = dout.toByteArray();

    byte[] retVal = new byte[2 + 2 + oidBytes.length + 4 + mechPortion.length];
    int pos = 0;
    retVal[pos++] = 0x04;
    retVal[pos++] = 0x01;
    retVal[pos++] = (byte) (oidBytes.length >>> 8);
    retVal[pos++] = (byte) oidBytes.length;
    System.arraycopy(oidBytes, 0, retVal, pos, oidBytes.length);
    pos += oidBytes.length;
    retVal[pos++] = (byte) (mechPortion.length >>> 24);
    retVal[pos++] = (byte) (mechPortion.length >>> 16);
    retVal[pos++] = (byte) (mechPortion.length >>> 8);
    retVal[pos++] = (byte) mechPortion.length;
    System.arraycopy(mechPortion, 0, retVal, pos, mechPortion.length);
    return retVal;
  }
예제 #5
0
  /* Translate to encoded bytes */
  private void emit(DerOutputStream out) throws IOException, CertificateEncodingException {
    DerOutputStream tagged = new DerOutputStream();

    if (forward != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(forward.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FORWARD), tmp);
    }

    if (reverse != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(reverse.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REVERSE), tmp);
    }

    out.write(DerValue.tag_Sequence, tagged);
  }
예제 #6
0
파일: APRep.java 프로젝트: ronshapiro/j86
 /**
  * Encodes an APRep object.
  *
  * @return byte array of encoded APRep object.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(pvno));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(msgType));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), encPart.asn1Encode());
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   DerOutputStream aprep = new DerOutputStream();
   aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0F), temp);
   return aprep.toByteArray();
 }