-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Do stricter validation of X.509 gossip cert in DAB transactions (
#16666) Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
- Loading branch information
1 parent
9068bfc
commit 81b7849
Showing
4 changed files
with
108 additions
and
29 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
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
55 changes: 55 additions & 0 deletions
55
...ava/com/hedera/node/app/service/addressbook/impl/validators/AddressBookValidatorTest.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,55 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.node.app.service.addressbook.impl.validators; | ||
|
||
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_GOSSIP_CA_CERTIFICATE; | ||
import static com.hedera.node.app.service.addressbook.AddressBookHelper.writeCertificatePemFile; | ||
import static com.hedera.node.app.service.addressbook.impl.test.handlers.AddressBookTestBase.generateX509Certificates; | ||
import static com.hedera.node.app.service.addressbook.impl.validators.AddressBookValidator.validateX509Certificate; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.hedera.node.app.spi.workflows.PreCheckException; | ||
import com.hedera.pbj.runtime.io.buffer.Bytes; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.security.cert.CertificateEncodingException; | ||
import java.security.cert.X509Certificate; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AddressBookValidatorTest { | ||
private static X509Certificate x509Cert; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
x509Cert = generateX509Certificates(1).getFirst(); | ||
} | ||
|
||
@Test | ||
void encodedCertPassesValidation() { | ||
assertDoesNotThrow(() -> validateX509Certificate(Bytes.wrap(x509Cert.getEncoded()))); | ||
} | ||
|
||
@Test | ||
void utf8EncodingOfX509PemFailsValidation() throws CertificateEncodingException, IOException { | ||
final var baos = new ByteArrayOutputStream(); | ||
writeCertificatePemFile(x509Cert.getEncoded(), baos); | ||
final var e = | ||
assertThrows(PreCheckException.class, () -> validateX509Certificate(Bytes.wrap(baos.toByteArray()))); | ||
assertEquals(INVALID_GOSSIP_CA_CERTIFICATE, e.responseCode()); | ||
} | ||
} |
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