-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cname encoding in CertificateGenerator (#20745)
* Fix cname encoding in CertificateGenerator * added license * Added changelog
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "fixed" | ||
message = "Fix encoding of CName in generated CA certificates" | ||
|
||
issues = ["20738"] | ||
pulls = ["20745"] |
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
47 changes: 47 additions & 0 deletions
47
graylog2-server/src/test/java/org/graylog/security/certutil/CertificateGeneratorTest.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,47 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog.security.certutil; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.security.cert.X509Certificate; | ||
import java.time.Duration; | ||
|
||
class CertificateGeneratorTest { | ||
|
||
@Test | ||
void testDomainName() throws Exception { | ||
final KeyPair pair = selfSigned("www.graylog.org"); | ||
final X509Certificate certificate = pair.certificate(); | ||
final String cn = certificate.getSubjectX500Principal().getName(); | ||
Assertions.assertThat(cn).isEqualTo("CN=www.graylog.org"); | ||
} | ||
|
||
@Test | ||
void testEscaping() throws Exception { | ||
final KeyPair pair = selfSigned("Graylog, Inc."); | ||
final X509Certificate certificate = pair.certificate(); | ||
final String cn = certificate.getSubjectX500Principal().getName(); | ||
Assertions.assertThat(cn).isEqualTo("CN=Graylog\\, Inc."); | ||
} | ||
|
||
private static KeyPair selfSigned(String cname) throws Exception { | ||
final CertRequest req = CertRequest.selfSigned(cname).validity(Duration.ofDays(1)); | ||
return CertificateGenerator.generate(req); | ||
} | ||
} |