Package org.w3._2002._03.xkms_

Examples of org.w3._2002._03.xkms_.UseKeyWithType


               
                getPrintStream().println("Sending locate request with id " + reqId + " to XKMS Service");
                if (clientCert == null) {
                    log.info("Client cert was not found and will not be used.");
                }
                LocateResultType locateResult = getXKMSInvoker().locate(locateRequestType, clientCert, privateKey);
                keyBindings = locateResult.getUnverifiedKeyBinding();                                               
            }

            if(keyBindings.size() > 0){
              getPrintStream().println("\n  The query matched " + keyBindings.size() + " certificates :");
              Iterator iter = keyBindings.iterator();
View Full Code Here


 
  /**
   * Returns a locate response
   */
  public LocateResultType getResponse(boolean requestVerifies){
    LocateResultType result = xkmsFactory.createLocateResultType();   
    super.populateResponse(result, requestVerifies);   
    LocateRequestType req = (LocateRequestType) this.req;
    if(resultMajor == null){    
      if(!checkValidRespondWithRequest(req.getRespondWith())){
        resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
        resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
      }
      if(resultMajor == null){
        List<X509Certificate> queryResult = processRequest(req.getQueryKeyBinding());
        if (log.isDebugEnabled()) {
          log.debug("processRequest returned " + queryResult.size() + " results.");
        }
        if(resultMajor == null){    
          Iterator<X509Certificate> iter = queryResult.iterator();
          while(iter.hasNext()){
            X509Certificate nextCert = iter.next();
            result.getUnverifiedKeyBinding().add((UnverifiedKeyBindingType) getResponseValues(req.getQueryKeyBinding(),nextCert,false,false));
          }     
        }
      }
    }
    if(resultMajor == null){
View Full Code Here

        locateRequestType.setResponseLimit(new BigInteger("3"));

        queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
        locateRequestType.setQueryKeyBinding(queryKeyBindingType);

        LocateResultType locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
        assertEquals("Wrong number of UnverifiedKeyBinding.", 3, locateResultType.getUnverifiedKeyBinding().size());

        // request with 2 and expect 2
        locateRequestType = xKMSObjectFactory.createLocateRequestType();
        locateRequestType.setId("301");
        queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
        useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
        useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_TLSHTTP);
        useKeyWithType.setIdentifier(baseUsername);
        locateRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CERT);
        locateRequestType.setResponseLimit(new BigInteger("2"));

        queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
        locateRequestType.setQueryKeyBinding(queryKeyBindingType);

        locateResultType = xKMSInvoker.locate(locateRequestType, null, null);
        assertTrue(locateResultType.getResultMajor().equals(XKMSConstants.RESULTMAJOR_SUCCESS));
        assertTrue(locateResultType.getResultMinor().equals(XKMSConstants.RESULTMINOR_TOOMANYRESPONSES));
    }
View Full Code Here

   * @param req
   * @return The password or null if no NotBoundAuthentication were found.
   */
    protected String getClearPassword(RequestAbstractType req, String dBPassword) {
    String retval = null;
    NotBoundAuthenticationType notBoundAuthenticationType = GeneralizedKRSSMessageHelper.getAuthenticationType(req).getNotBoundAuthentication();
    if(notBoundAuthenticationType != null){
      retval = new String(notBoundAuthenticationType.getValue());
    }else{
      resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
      resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
    }
   
View Full Code Here

    }

    public void test01AbstractType() throws Exception {
        LocateRequestType abstractRequestType = xKMSObjectFactory.createLocateRequestType();
        abstractRequestType.setId("123");
        OpaqueClientDataType opaqueClientDataType = new OpaqueClientDataType();
        opaqueClientDataType.getOpaqueData().add("TEST".getBytes());
        opaqueClientDataType.getOpaqueData().add("TEST2".getBytes());
        QueryKeyBindingType queryKeyBindingType = xKMSObjectFactory.createQueryKeyBindingType();
        abstractRequestType.setQueryKeyBinding(queryKeyBindingType);

        abstractRequestType.setOpaqueClientData(opaqueClientDataType);
        LocateResultType abstractResultType = xKMSInvoker.locate(abstractRequestType, null, null);
        assertTrue(abstractResultType.getRequestId().equals("123"));
        assertTrue(!abstractResultType.getId().equals("123"));

        OpaqueClientDataType opaqueClientDataTypeResult = abstractResultType.getOpaqueClientData();
        assertTrue(opaqueClientDataTypeResult.getOpaqueData().size() == 2);
        assertTrue(new String(opaqueClientDataTypeResult.getOpaqueData().get(0)).equals("TEST"));
        assertTrue(new String(opaqueClientDataTypeResult.getOpaqueData().get(1)).equals("TEST2"));

    }
View Full Code Here

        DocumentBuilder db = dbf.newDocumentBuilder();
        KeyPair keys = KeyTools.genKeys("1024", "RSA");                               
        RegisterResultType registerResultType = xKMSObjectFactory.createRegisterResultType();
        JAXBElement<RegisterResultType> registerResult = xKMSObjectFactory.createRegisterResult(registerResultType);
               
        PrivateKeyType privateKeyType1 = XKMSUtil.getEncryptedXMLFromPrivateKey( (RSAPrivateCrtKey) keys.getPrivate(), "This is total crap");
        registerResultType.setPrivateKey(privateKeyType1);
       
        Document registerResultDoc = db.newDocument();
        marshaller.marshal( registerResult, registerResultDoc );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLUtils.outputDOM(registerResultDoc, baos);
        log.debug("XMLUtils.outputDOM: " + baos.toString());
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        JAXBElement<RegisterResultType> registerResult2 = (JAXBElement<RegisterResultType>) unmarshaller.unmarshal(bais);
        registerResultType = registerResult2.getValue();
       
        PrivateKeyType privateKeyType2 = registerResultType.getPrivateKey();
        RSAPrivateKey privkey2 = XKMSUtil.getPrivateKeyFromEncryptedXML(privateKeyType2, "This is total crap");
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,privkey2, keys.getPublic(), "SHA1WithRSA", true);
        cert.verify(keys.getPublic());   
    }   
View Full Code Here

   * @return The Document with the encrypted key included.
   * @throws StringprepException if the shared secret doesn't conform with the SASLprep profile as specified in the XKMS specification.
   * @throws XMLEncryptionException if any other exception occurs during the processing.
   */
  public static PrivateKeyType getEncryptedXMLFromPrivateKey(RSAPrivateCrtKey rSAPrivateKey, String sharedSecret) throws StringprepException, XMLEncryptionException{
    PrivateKeyType privateKeyType = null;
    try{
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document rSAKeyPairDoc = db.newDocument();

        SecretKey sk = getSecretKeyFromPassphrase(sharedSecret,true, 24, KEY_PRIVATEKEYDATA);
       
        RSAKeyPairType rSAKeyPairType = xKMSObjectFactory.createRSAKeyPairType();
      
        rSAKeyPairType.setModulus(rSAPrivateKey.getModulus().toByteArray());
        rSAKeyPairType.setExponent(rSAPrivateKey.getPublicExponent().toByteArray());
        rSAKeyPairType.setP(rSAPrivateKey.getPrimeP().toByteArray());
        rSAKeyPairType.setQ(rSAPrivateKey.getPrimeQ().toByteArray());
        rSAKeyPairType.setDP(rSAPrivateKey.getPrimeExponentP().toByteArray());
        rSAKeyPairType.setDQ(rSAPrivateKey.getPrimeExponentQ().toByteArray());
        rSAKeyPairType.setInverseQ(rSAPrivateKey.getCrtCoefficient().toByteArray());
        rSAKeyPairType.setD(rSAPrivateKey.getPrivateExponent().toByteArray());

        JAXBElement<RSAKeyPairType> rSAKeyPair = xKMSObjectFactory.createRSAKeyPair(rSAKeyPairType);

    marshaller.marshal( rSAKeyPair, rSAKeyPairDoc );

    Document envelopedDoc = db.newDocument();
    Element unencryptedElement = envelopedDoc.createElement("PrivateKey");
    envelopedDoc.appendChild(unencryptedElement);
    Element node = (Element) envelopedDoc.adoptNode(rSAKeyPairDoc.getDocumentElement());
    unencryptedElement.appendChild(node);
   
        Element rootElement = envelopedDoc.getDocumentElement();
      
       
        XMLCipher xmlCipher =
            XMLCipher.getProviderInstance(ENCRYPTION_ALGORITHMURI,"BC");
        xmlCipher.init(XMLCipher.ENCRYPT_MODE, sk);

        EncryptedData encryptedData = xmlCipher.getEncryptedData();
        encryptedData.setMimeType("text/xml");
       
        xmlCipher.doFinal(envelopedDoc,rootElement,true);     

        JAXBElement unmarshalledData = (JAXBElement) unmarshaller.unmarshal(envelopedDoc.getDocumentElement().getFirstChild());
       
        EncryptedDataType encryptedDataType = (EncryptedDataType) unmarshalledData.getValue();
        privateKeyType = xKMSObjectFactory.createPrivateKeyType();
        privateKeyType.setEncryptedData(encryptedDataType);
       
    } catch (ParserConfigurationException e) {
      log.error("Error encryption private key", e);
      throw new XMLEncryptionException(e.getMessage(),e);
    } catch (XMLSecurityException e) {
View Full Code Here

            if(keySize != 0){
              genKeys = KeyTools.genKeys(Integer.toString(keySize), "RSA");
            }
           
            String keyBindingId = genId();           
            PrototypeKeyBindingType prototypeKeyBinding = xKMSObjectFactory.createPrototypeKeyBindingType();
            prototypeKeyBinding.setId(keyBindingId);
            UseKeyWithType useKeyWithType = xKMSObjectFactory.createUseKeyWithType();
            useKeyWithType.setApplication(XKMSConstants.USEKEYWITH_PKIX);
            useKeyWithType.setIdentifier(subjectDN);           
            prototypeKeyBinding.getUseKeyWith().add(useKeyWithType);
           
            if(revocationCodeId != null && !revocationCodeId.equalsIgnoreCase("NULL")){
                byte[] first = XKMSUtil.getSecretKeyFromPassphrase(revocationCodeId, true,20, XKMSUtil.KEY_REVOCATIONCODEIDENTIFIER_PASS1).getEncoded();
                byte[] second = XKMSUtil.getSecretKeyFromPassphrase(new String(first,"ISO8859-1"), false,20, XKMSUtil.KEY_REVOCATIONCODEIDENTIFIER_PASS2).getEncoded();
                prototypeKeyBinding.setRevocationCodeIdentifier(second);
            }
           
            String reqId = genId();
            RegisterRequestType registerRequestType = xKMSObjectFactory.createRegisterRequestType();
            registerRequestType.setId(reqId);
            registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);
            if(keySize == 0){
              registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_PRIVATEKEY);
            }
            registerRequestType.setPrototypeKeyBinding(prototypeKeyBinding);
           
            RegisterResultType registerResultType = null;
            if(genKeys == null){
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, null, keyBindingId);
            }else{
              KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
                RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
                rsaKeyValueType.setExponent(((RSAPublicKey) genKeys.getPublic()).getPublicExponent().toByteArray());
                rsaKeyValueType.setModulus(((RSAPublicKey) genKeys.getPublic()).getModulus().toByteArray());
                JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
                keyInfoType.getContent().add(rsaKeyValue);
               
                prototypeKeyBinding.setKeyInfo(keyInfoType);
             
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, genKeys.getPrivate(), keyBindingId);             
            }
           
            if(registerResultType.getResultMajor().equals(XKMSConstants.RESULTMAJOR_SUCCESS) &&
View Full Code Here

        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) keys.getPublic()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) keys.getPublic()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);               
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = db.newDocument();
        marshaller.marshal( registerRequest, registerRequestDoc );
View Full Code Here

        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) pkCert.getPublicKey()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) pkCert.getPublicKey()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = dbf.newDocumentBuilder().newDocument();
        marshaller.marshal(registerRequest, registerRequestDoc);

        Element prototypeKeyBindingTag = (Element) registerRequestDoc.getDocumentElement().getElementsByTagNameNS("http://www.w3.org/2002/03/xkms#",
                "PrototypeKeyBinding").item(0);
        assertTrue(prototypeKeyBindingTag != null);

        org.apache.xml.security.signature.XMLSignature xmlSig = new org.apache.xml.security.signature.XMLSignature(registerRequestDoc, "",
                org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1,
                org.apache.xml.security.c14n.Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
        org.apache.xml.security.transforms.Transforms transforms = new org.apache.xml.security.transforms.Transforms(registerRequestDoc);
        transforms.addTransform(org.apache.xml.security.transforms.Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
        xmlSig.addDocument("#" + prototypeKeyBindingType.getId(), transforms, org.apache.xml.security.utils.Constants.ALGO_ID_DIGEST_SHA1);

        xmlSig.sign(key);

        Element pOPElement = registerRequestDoc.createElementNS("http://www.w3.org/2002/03/xkms#", "ProofOfPossession");
        pOPElement.appendChild(xmlSig.getElement().cloneNode(true));
View Full Code Here

TOP

Related Classes of org.w3._2002._03.xkms_.UseKeyWithType

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.