Skip to content

Commit bddbdcd

Browse files
author
Daniel DeGroff
committed
Remove un-needed line return at the end of the PEM when encoding.
1 parent 47b1d39 commit bddbdcd

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FusionAuth JWT Changes
22

3+
Changes in 3.0.1
4+
* Remove un-needed line return at the end of the PEM when encoding a PEM string.
5+
36
Changes in 3.0.0
47

58
This major version of fusionauth-jwt contains breaking changes.

build.savant

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ savantVersion = "1.0.0"
1818
jacksonVersion = "2.9.8"
1919
jacksonAnnotationVersion = "2.9.6"
2020

21-
project(group: "io.fusionauth", name: "fusionauth-jwt", version: "3.0.0", licenses: ["ApacheV2_0"]) {
21+
project(group: "io.fusionauth", name: "fusionauth-jwt", version: "3.0.1", licenses: ["ApacheV2_0"]) {
2222

2323
workflow {
2424
standard()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.fusionauth</groupId>
88
<artifactId>fusionauth-jwt</artifactId>
9-
<version>3.0.0</version>
9+
<version>3.0.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>FusionAuth JWT</name>

src/main/java/io/fusionauth/pem/PEMEncoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ private void addClosingTag(Key key, StringBuilder sb) {
160160
sb.append("\n");
161161
if (key instanceof PrivateKey) {
162162
if (key.getFormat().equals("PKCS#1")) {
163-
sb.append(PEM.PKCS_1_PRIVATE_KEY_SUFFIX).append("\n");
163+
sb.append(PEM.PKCS_1_PRIVATE_KEY_SUFFIX);
164164
} else if (key.getFormat().equals("PKCS#8")) {
165-
sb.append(PEM.PKCS_8_PRIVATE_KEY_SUFFIX).append("\n");
165+
sb.append(PEM.PKCS_8_PRIVATE_KEY_SUFFIX);
166166
}
167167
} else {
168-
sb.append(PEM.X509_PUBLIC_KEY_SUFFIX).append("\n");
168+
sb.append(PEM.X509_PUBLIC_KEY_SUFFIX);
169169
}
170170
}
171171

src/test/java/io/fusionauth/pem/PEMEncoderTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public void ec() throws Exception {
4646
String encodedPublicKey = PEM.encode(keyPair.getPublic());
4747
assertNotNull(encodedPublicKey);
4848
assertTrue(encodedPublicKey.startsWith(PEM.X509_PUBLIC_KEY_PREFIX));
49-
assertTrue(encodedPublicKey.endsWith(PEM.X509_PUBLIC_KEY_SUFFIX + "\n"));
49+
assertTrue(encodedPublicKey.endsWith(PEM.X509_PUBLIC_KEY_SUFFIX));
5050

5151
String encodedPrivateKey = PEM.encode(keyPair.getPrivate());
5252
assertNotNull(encodedPrivateKey);
5353
assertTrue(encodedPrivateKey.startsWith(PEM.PKCS_8_PRIVATE_KEY_PREFIX));
54-
assertTrue(encodedPrivateKey.endsWith(PEM.PKCS_8_PRIVATE_KEY_SUFFIX + "\n"));
54+
assertTrue(encodedPrivateKey.endsWith(PEM.PKCS_8_PRIVATE_KEY_SUFFIX));
5555

5656
// Since we built our own key pair, the private key will not contain the public key
5757
PEM pem = PEM.decode(encodedPrivateKey);
@@ -69,8 +69,8 @@ public void ec() throws Exception {
6969
@Test
7070
public void ec_backAndForth() throws Exception {
7171
// Start with openSSL PKCS#8 private key and X.509 public key
72-
String expectedPrivate = new String(Files.readAllBytes(Paths.get("src/test/resources/ec_private_prime256v1_p_256_openssl_pkcs8.pem")));
73-
String expectedPublic = new String(Files.readAllBytes(Paths.get("src/test/resources/ec_public_prime256v1_p_256_openssl.pem")));
72+
String expectedPrivate = new String(Files.readAllBytes(Paths.get("src/test/resources/ec_private_prime256v1_p_256_openssl_pkcs8.pem"))).trim();
73+
String expectedPublic = new String(Files.readAllBytes(Paths.get("src/test/resources/ec_public_prime256v1_p_256_openssl.pem"))).trim();
7474

7575
// Decode the private key to ensure we get both private and public keys out of the private PEM
7676
PEM pem = PEM.decode(expectedPrivate);
@@ -103,12 +103,12 @@ public void rsa() throws Exception {
103103
String encodedPublicKey = PEM.encode(keyPair.getPublic());
104104
assertNotNull(encodedPublicKey);
105105
assertTrue(encodedPublicKey.startsWith(PEM.X509_PUBLIC_KEY_PREFIX));
106-
assertTrue(encodedPublicKey.endsWith(PEM.X509_PUBLIC_KEY_SUFFIX + "\n"));
106+
assertTrue(encodedPublicKey.endsWith(PEM.X509_PUBLIC_KEY_SUFFIX));
107107

108108
String encodedPrivateKey = PEM.encode(keyPair.getPrivate());
109109
assertNotNull(encodedPrivateKey);
110110
assertTrue(encodedPrivateKey.startsWith(PEM.PKCS_8_PRIVATE_KEY_PREFIX));
111-
assertTrue(encodedPrivateKey.endsWith(PEM.PKCS_8_PRIVATE_KEY_SUFFIX + "\n"));
111+
assertTrue(encodedPrivateKey.endsWith(PEM.PKCS_8_PRIVATE_KEY_SUFFIX));
112112

113113
// Since the public RSA modulus and public exponent are always included in the private key, they should
114114
// be contained in the generated PEM
@@ -120,8 +120,8 @@ public void rsa() throws Exception {
120120
@Test
121121
public void rsa_backAndForth_pkcs_1() throws Exception {
122122
// Start externally created PKCS#1 private key and X.509 public key
123-
String expectedPrivate_pkcs_1 = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_1_control.pem")));
124-
String expectedPrivate_pkcs_8 = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem")));
123+
String expectedPrivate_pkcs_1 = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_1_control.pem"))).trim();
124+
String expectedPrivate_pkcs_8 = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem"))).trim();
125125
String expectedPublic = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_public_key_2048_x509_control.pem")));
126126

127127
// Decode the private key to ensure we get both private and public keys out of the private PEM
@@ -146,14 +146,14 @@ public void rsa_backAndForth_pkcs_1() throws Exception {
146146

147147
// Re-encode the public key to PEM X.509 format and ensure it equals the original
148148
String encodedPublicKey = PEM.encode(pem.getPublicKey());
149-
assertEquals(encodedPublicKey, expectedPublic + "\n");
149+
assertEquals(encodedPublicKey, expectedPublic);
150150
}
151151

152152
@Test
153153
public void rsa_backAndForth_pkcs_8() throws Exception {
154154
// Start externally created PKCS#1 private key and X.509 public key
155-
String expectedPrivate = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem")));
156-
String expectedPublic = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_public_key_2048_x509_control.pem")));
155+
String expectedPrivate = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem"))).trim();
156+
String expectedPublic = new String(Files.readAllBytes(Paths.get("src/test/resources/rsa_public_key_2048_x509_control.pem"))).trim();
157157

158158
// Decode the private key to ensure we get both private and public keys out of the private PEM
159159
PEM pem = PEM.decode(expectedPrivate);
@@ -175,6 +175,6 @@ public void rsa_backAndForth_pkcs_8() throws Exception {
175175

176176
// Re-encode the public key to PEM X.509 format and ensure it equals the original
177177
String encodedPublicKey = PEM.encode(pem.getPublicKey());
178-
assertEquals(encodedPublicKey, expectedPublic + "\n");
178+
assertEquals(encodedPublicKey, expectedPublic);
179179
}
180180
}

0 commit comments

Comments
 (0)