Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for EC mTLS keys (#4920)
* Add support for EC mTlS keys * Revert change to integration test
- Loading branch information
Showing
2 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
63 changes: 63 additions & 0 deletions
63
exporters/common/src/test/java/io/opentelemetry/exporter/internal/TlsUtilTest.java
This file contains 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,63 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import com.linecorp.armeria.internal.common.util.SelfSignedCertificate; | ||
import java.security.KeyFactory; | ||
import java.security.cert.CertificateException; | ||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.time.Instant; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import javax.net.ssl.SSLException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TlsUtilTest { | ||
|
||
private SelfSignedCertificate rsaCertificate; | ||
private SelfSignedCertificate ecCertificate; | ||
|
||
@BeforeEach | ||
void setup() throws CertificateException { | ||
rsaCertificate = | ||
new SelfSignedCertificate(Date.from(Instant.now()), Date.from(Instant.now()), "RSA", 2048); | ||
ecCertificate = | ||
new SelfSignedCertificate(Date.from(Instant.now()), Date.from(Instant.now()), "EC", 256); | ||
} | ||
|
||
@Test | ||
void keyManager_Rsa() { | ||
assertThatCode( | ||
() -> | ||
TlsUtil.keyManager( | ||
rsaCertificate.key().getEncoded(), rsaCertificate.cert().getEncoded())) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void keyManager_Ec() { | ||
assertThatCode( | ||
() -> | ||
TlsUtil.keyManager( | ||
ecCertificate.key().getEncoded(), ecCertificate.cert().getEncoded())) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void generatePrivateKey_Invalid() { | ||
PKCS8EncodedKeySpec keySpec = | ||
new PKCS8EncodedKeySpec(TlsUtil.decodePem(rsaCertificate.key().getEncoded())); | ||
assertThatCode( | ||
() -> | ||
TlsUtil.generatePrivateKey( | ||
keySpec, Collections.singletonList(KeyFactory.getInstance("EC")))) | ||
.isInstanceOf(SSLException.class) | ||
.hasMessage("Unable to generate key from supported algorithms: [EC]"); | ||
} | ||
} |