-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#784 Don't try plugins if they will not work on current protocol
- Loading branch information
1 parent
607d2e8
commit 3ece8a4
Showing
10 changed files
with
276 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
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
62 changes: 62 additions & 0 deletions
62
...lugin/src/test/java/org/firebirdsql/jaybird/chacha64/ChaCha64EncryptionPluginSpiTest.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,62 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* 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 | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.jaybird.chacha64; | ||
|
||
import org.firebirdsql.gds.ng.wire.crypt.CryptConnectionInfo; | ||
import org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION13; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION15; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION16; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION18; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author Mark Rotteveel | ||
*/ | ||
class ChaCha64EncryptionPluginSpiTest { | ||
|
||
@Test | ||
void encryptionIdentifier() { | ||
assertEquals(new EncryptionIdentifier("Symmetric", "ChaCha64"), new ChaCha64EncryptionPluginSpi().encryptionIdentifier()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = { PROTOCOL_VERSION16, PROTOCOL_VERSION18 }) | ||
void isSupported_true(int protocolVersion) { | ||
assertTrue(new ChaCha64EncryptionPluginSpi().isSupported(new ConnectionInfoImpl(protocolVersion))); | ||
} | ||
|
||
@ParameterizedTest | ||
// NOTE: Implementation also reports false for PROTOCOL_VERSION10 - 12, which don't support wire encryption, | ||
// but we don't check those versions | ||
@ValueSource(ints = { PROTOCOL_VERSION13, PROTOCOL_VERSION15 }) | ||
void isSupported_false(int protocolVersion) { | ||
assertFalse(new ChaCha64EncryptionPluginSpi().isSupported(new ConnectionInfoImpl(protocolVersion))); | ||
} | ||
|
||
private record ConnectionInfoImpl(int protocolVersion) implements CryptConnectionInfo { | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/org/firebirdsql/gds/ng/wire/crypt/CryptConnectionInfo.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,42 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* 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 | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.gds.ng.wire.crypt; | ||
|
||
/** | ||
* Details of the connection, which the SPI can use to decide if they can work. | ||
* <p> | ||
* NOTE: This class is currently only internal to Jaybird, consider the API as unstable. | ||
* </p> | ||
* | ||
* @author Mark Rotteveel | ||
* @since 6 | ||
*/ | ||
public interface CryptConnectionInfo { | ||
|
||
/** | ||
* Protocol version of the connection. | ||
* <p> | ||
* The protocol version is masked, so use the relevant {@code PROTOCOL_VERSIONnn} constants from | ||
* {@link org.firebirdsql.gds.impl.wire.WireProtocolConstants} or equivalents for checks. | ||
* </p> | ||
* | ||
* @return protocol version, {@code 0} means unknown (shouldn't occur normally) | ||
*/ | ||
int protocolVersion(); | ||
} |
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
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
src/test/org/firebirdsql/gds/ng/wire/crypt/arc4/Arc4EncryptionPluginSpiTest.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 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* 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 | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.gds.ng.wire.crypt.arc4; | ||
|
||
import org.firebirdsql.gds.ng.wire.crypt.CryptConnectionInfo; | ||
import org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION13; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION15; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION16; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION18; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Tests for {@link Arc4EncryptionPluginSpi}. | ||
*/ | ||
class Arc4EncryptionPluginSpiTest { | ||
|
||
@Test | ||
void encryptionIdentifier() { | ||
assertEquals(new EncryptionIdentifier("Symmetric", "Arc4"), new Arc4EncryptionPluginSpi().encryptionIdentifier()); | ||
} | ||
|
||
@ParameterizedTest | ||
// NOTE: Implementation always reports true, also for PROTOCOL_VERSION10 - 12, which don't support wire encryption, | ||
// but we don't check those versions | ||
@ValueSource(ints = { PROTOCOL_VERSION13, PROTOCOL_VERSION15, PROTOCOL_VERSION16, PROTOCOL_VERSION18 }) | ||
void isSupported_true(int protocolVersion) { | ||
assertTrue(new Arc4EncryptionPluginSpi().isSupported(new ConnectionInfoImpl(protocolVersion))); | ||
} | ||
|
||
private record ConnectionInfoImpl(int protocolVersion) implements CryptConnectionInfo { | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/test/org/firebirdsql/gds/ng/wire/crypt/chacha/ChaChaEncryptionPluginSpiTest.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,62 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* 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 | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.gds.ng.wire.crypt.chacha; | ||
|
||
import org.firebirdsql.gds.ng.wire.crypt.CryptConnectionInfo; | ||
import org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION13; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION15; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION16; | ||
import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.PROTOCOL_VERSION18; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Tests for {@link ChaChaEncryptionPluginSpi}. | ||
*/ | ||
class ChaChaEncryptionPluginSpiTest { | ||
|
||
@Test | ||
void encryptionIdentifier() { | ||
assertEquals(new EncryptionIdentifier("Symmetric", "ChaCha"), new ChaChaEncryptionPluginSpi().encryptionIdentifier()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = { PROTOCOL_VERSION16, PROTOCOL_VERSION18 }) | ||
void isSupported_true(int protocolVersion) { | ||
assertTrue(new ChaChaEncryptionPluginSpi().isSupported(new ConnectionInfoImpl(protocolVersion))); | ||
} | ||
|
||
@ParameterizedTest | ||
// NOTE: Implementation also reports false for PROTOCOL_VERSION10 - 12, which don't support wire encryption, | ||
// but we don't check those versions | ||
@ValueSource(ints = { PROTOCOL_VERSION13, PROTOCOL_VERSION15 }) | ||
void isSupported_false(int protocolVersion) { | ||
assertFalse(new ChaChaEncryptionPluginSpi().isSupported(new ConnectionInfoImpl(protocolVersion))); | ||
} | ||
|
||
private record ConnectionInfoImpl(int protocolVersion) implements CryptConnectionInfo { | ||
} | ||
|
||
} |