-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-8605. Implement the ability to update the ServiceInfo object with the new rootCA #5009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5ec0d6f
HDDS-8605. Implement the ability to update the ServiceInfo object wit…
fapifta 527435a
Address simple review comments.
fapifta 311582a
Add client tests, to check if the client properly gets the new root C…
fapifta df0d4de
Adding/extending API doc to newly added classes.
fapifta ec9e526
Reduced the visibility of the class, as we should not need it outside…
fapifta 8a6e152
Address further review comments.
fapifta bff7281
Fix container reference in ozonesecure-ha test. Check for all OMs see…
fapifta 5807781
Clean some code after changes in toPEMEncodedStringUnsafe based on re…
fapifta 4808327
Remove unused import.
fapifta bbde3d8
Avoid registering any listener to the poller when the automatic rotat…
fapifta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/x509/keys/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * 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. | ||
| * | ||
| */ | ||
|
|
||
| /** | ||
| * Utils for private and public keys. | ||
| */ | ||
| package org.apache.hadoop.hdds.security.x509.keys; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...-hdds/common/src/test/java/org/apache/hadoop/hdds/security/x509/CertificateTestUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* | ||
| * 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.hadoop.hdds.security.x509; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.security.SecurityConfig; | ||
| import org.apache.hadoop.hdds.security.x509.keys.HDDSKeyGenerator; | ||
| import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; | ||
| import org.bouncycastle.asn1.x500.X500Name; | ||
| import org.bouncycastle.asn1.x509.AlgorithmIdentifier; | ||
| import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; | ||
| import org.bouncycastle.asn1.x509.BasicConstraints; | ||
| import org.bouncycastle.asn1.x509.Extension; | ||
| import org.bouncycastle.asn1.x509.SubjectKeyIdentifier; | ||
| import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; | ||
| import org.bouncycastle.cert.X509ExtensionUtils; | ||
| import org.bouncycastle.cert.X509v3CertificateBuilder; | ||
| import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; | ||
| import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder; | ||
| import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
| import org.bouncycastle.operator.ContentSigner; | ||
| import org.bouncycastle.operator.DigestCalculator; | ||
| import org.bouncycastle.operator.OperatorCreationException; | ||
| import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; | ||
| import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.security.KeyPair; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.security.NoSuchProviderException; | ||
| import java.security.cert.X509Certificate; | ||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * Test utilities to create simple certificates/keys for testing. | ||
| */ | ||
| public final class CertificateTestUtils { | ||
| private CertificateTestUtils() { } | ||
|
|
||
| private static final String HASH_ALGO = "SHA256WithRSA"; | ||
|
|
||
| /** | ||
| * Generates a keypair using the HDDSKeyGenerator with the given config. | ||
| * | ||
| * @param conf the config applies to keys | ||
| * | ||
| * @return a newly generated keypair | ||
| * | ||
| * @throws NoSuchProviderException on wrong security provider in the config | ||
| * @throws NoSuchAlgorithmException on wrong encryption algo in the config | ||
| */ | ||
| public static KeyPair aKeyPair(ConfigurationSource conf) | ||
| throws NoSuchProviderException, NoSuchAlgorithmException { | ||
| return new HDDSKeyGenerator(new SecurityConfig(conf)).generateKey(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a self-signed certificate and returns it as an X509Certificate. | ||
| * The given keys and common name are being used in the certificate. | ||
| * The certificate will have its serial id generated based on the hashcode | ||
| * of the public key, and will expire after 1 day. | ||
| * | ||
| * @param keys the keypair to use for the certificate | ||
| * @param commonName the common name used in the certificate | ||
| * | ||
| * @return the X509Certificate representing a self-signed certificate | ||
| * | ||
| * @throws Exception in case any error occurs during the certificate creation | ||
| */ | ||
| public static X509Certificate createSelfSignedCert(KeyPair keys, | ||
| String commonName) throws Exception { | ||
| return createSelfSignedCert(keys, commonName, Duration.ofDays(1)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a self-signed certificate and returns it as an X509Certificate. | ||
| * The given keys and common name are being used in the certificate. | ||
| * The certificate will have its serial id generated based on the hashcode | ||
| * of the public key, and will expire after the specified duration. | ||
| * | ||
| * @param keys the keypair to use for the certificate | ||
| * @param commonName the common name used in the certificate | ||
| * @param expiresIn the lifespan of the certificate | ||
| * | ||
| * @return the X509Certificate representing a self-signed certificate | ||
| * | ||
| * @throws Exception in case any error occurs during the certificate creation | ||
| */ | ||
| public static X509Certificate createSelfSignedCert(KeyPair keys, | ||
| String commonName, Duration expiresIn) throws Exception { | ||
| final Instant now = Instant.now(); | ||
| final Date notBefore = Date.from(now); | ||
| final Date notAfter = Date.from(now.plus(expiresIn)); | ||
| final ContentSigner contentSigner = | ||
| new JcaContentSignerBuilder(HASH_ALGO).build(keys.getPrivate()); | ||
| final X500Name x500Name = new X500Name("CN=" + commonName); | ||
|
|
||
| SubjectKeyIdentifier keyId = subjectKeyIdOf(keys); | ||
| AuthorityKeyIdentifier authorityKeyId = authorityKeyIdOf(keys); | ||
| BasicConstraints constraints = new BasicConstraints(true); | ||
|
|
||
| final X509v3CertificateBuilder certificateBuilder = | ||
| new JcaX509v3CertificateBuilder( | ||
| x500Name, | ||
| BigInteger.valueOf(keys.getPublic().hashCode()), | ||
| notBefore, | ||
| notAfter, | ||
| x500Name, | ||
| keys.getPublic() | ||
| ); | ||
| certificateBuilder | ||
| .addExtension(Extension.subjectKeyIdentifier, false, keyId) | ||
| .addExtension(Extension.authorityKeyIdentifier, false, authorityKeyId) | ||
| .addExtension(Extension.basicConstraints, true, constraints); | ||
|
|
||
| return new JcaX509CertificateConverter() | ||
| .setProvider(new BouncyCastleProvider()) | ||
| .getCertificate(certificateBuilder.build(contentSigner)); | ||
| } | ||
|
|
||
| private static SubjectKeyIdentifier subjectKeyIdOf(KeyPair keys) | ||
| throws Exception { | ||
| return extensionUtil().createSubjectKeyIdentifier(pubKeyInfo(keys)); | ||
| } | ||
|
|
||
| private static AuthorityKeyIdentifier authorityKeyIdOf(KeyPair keys) | ||
| throws Exception { | ||
| return extensionUtil().createAuthorityKeyIdentifier(pubKeyInfo(keys)); | ||
| } | ||
|
|
||
| private static SubjectPublicKeyInfo pubKeyInfo(KeyPair keys) { | ||
| return SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded()); | ||
| } | ||
|
|
||
| private static X509ExtensionUtils extensionUtil() | ||
| throws OperatorCreationException { | ||
| DigestCalculator digest = | ||
| new BcDigestCalculatorProvider() | ||
| .get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1)); | ||
|
|
||
| return new X509ExtensionUtils(digest); | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually generates the same id for the certificate over and over again and hides it away from the invoker. I think for a utility method like this it would be better to generate a new id or explicitly specify that the same keypair will generate the same id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a utility method, I could design it only for the use case I have at hand. I am adjusting the documentation, but I think we should not overengineer it here, once someone needs some other functionality, we can add it at that point in time either via an overload or via a new parameter and adjusted code where it is used.