seanjmullan commented on code in PR #234: URL: https://github.com/apache/santuario-xml-security-java/pull/234#discussion_r1420685122
########## src/main/java/org/apache/xml/security/encryption/params/KeyAgreementParameterSpec.java: ########## @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.xml.security.encryption.params; + +import java.security.KeyPair; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.AlgorithmParameterSpec; + +/** + * This class is used to pass parameters to the KeyAgreement algorithm. + */ +public class KeyAgreementParameterSpec implements AlgorithmParameterSpec { + /** + * This enum defines the actor type of the KeyAgreement algorithm. The actor type defines which public and which + * private key is expected to be present for the KeyAgreement algorithm to define derived key. + */ + public enum ActorType { + ORIGINATOR, + RECIPIENT + } + + private final KeyDerivationParameter KeyDerivationParameter; + private final ActorType actorType; + private final String keyAgreementAlgorithm; + + private PublicKey originatorPublicKey; + private PrivateKey originatorPrivateKey; + private PublicKey recipientPublicKey; + private PrivateKey recipientPrivateKey; + + + public KeyAgreementParameterSpec(ActorType actorType, String keyAgreementAlgorithm, KeyDerivationParameter keyDerivationParameter) { + this.actorType = actorType; + this.KeyDerivationParameter = keyDerivationParameter; + this.keyAgreementAlgorithm = keyAgreementAlgorithm; + } + + public KeyDerivationParameter getKeyDerivationParameter() { + return KeyDerivationParameter; + } + + public String getKeyAgreementAlgorithm() { + return keyAgreementAlgorithm; + } + + public void setOriginatorKeyPair(KeyPair originatorKeyPair) { + this.originatorPublicKey = originatorKeyPair.getPublic(); + this.originatorPrivateKey = originatorKeyPair.getPrivate(); + } + + public PublicKey getOriginatorPublicKey() { + return originatorPublicKey; + } + + public void setOriginatorPublicKey(PublicKey originatorPublicKey) { Review Comment: What about throwing `IllegalStateException` in this method if the `ActorType` is not `RECIPIENT`? Same comment for other set methods. ########## src/main/java/org/apache/xml/security/encryption/params/KeyAgreementParameterSpec.java: ########## @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.xml.security.encryption.params; + +import java.security.KeyPair; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.AlgorithmParameterSpec; + +/** + * This class is used to pass parameters to the KeyAgreement algorithm. + */ +public class KeyAgreementParameterSpec implements AlgorithmParameterSpec { Review Comment: Same comment about extending `AlgorithmParameterSpec` here - not sure it is necessary. ########## src/main/java/org/apache/xml/security/exceptions/DERDecodingException.java: ########## @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.xml.security.exceptions; + +/** + * This Exception is thrown if decoding of ANS1 (DER) data fails. Review Comment: Typo: s/ANS1/ASN.1/ ########## src/main/java/org/apache/xml/security/encryption/params/KeyDerivationParameter.java: ########## @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.xml.security.encryption.params; + +import java.security.spec.AlgorithmParameterSpec; + +/** + * This class contains the basic parameters used for key derivation. + */ +public class KeyDerivationParameter implements AlgorithmParameterSpec { Review Comment: It seems to be at the wrong abstraction layer (JCE vs XML Enc). Also, a KDF API is planned for a future Java SE release, so it probably makes sense to wait for that. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
