Skip to content

Commit f7c74e5

Browse files
committed
Expect PEM-encoded sealing key
1 parent 4b6688f commit f7c74e5

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

node-repository/src/main/java/com/yahoo/vespa/hosted/provision/backup/Snapshots.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.yahoo.config.provision.HostName;
1111
import com.yahoo.config.provision.NodeType;
1212
import com.yahoo.config.provision.SnapshotId;
13+
import com.yahoo.security.KeyAlgorithm;
1314
import com.yahoo.security.KeyId;
1415
import com.yahoo.security.KeyUtils;
1516
import com.yahoo.security.SealedSharedKey;
@@ -28,9 +29,8 @@
2829
import com.yahoo.vespa.hosted.provision.provisioning.SnapshotStore;
2930

3031
import java.security.KeyPair;
32+
import java.security.PrivateKey;
3133
import java.security.PublicKey;
32-
import java.security.interfaces.XECPrivateKey;
33-
import java.security.interfaces.XECPublicKey;
3434
import java.time.Instant;
3535
import java.util.ArrayList;
3636
import java.util.List;
@@ -196,8 +196,12 @@ private VersionedKeyPair sealingKeyPair(SecretVersionId version) {
196196
}
197197
Key key = Key.fromString(sealingPrivateKeySecretName.get());
198198
Secret sealingPrivateKey = version == null ? secretStore.getSecret(key) : secretStore.getSecret(key, version);
199-
XECPrivateKey privateKey = KeyUtils.fromBase64EncodedX25519PrivateKey(sealingPrivateKey.secretValue().value());
200-
XECPublicKey publicKey = KeyUtils.extractX25519PublicKey(privateKey);
199+
PrivateKey privateKey = KeyUtils.fromPemEncodedPrivateKey(sealingPrivateKey.secretValue().value());
200+
PublicKey publicKey = KeyUtils.extractPublicKey(privateKey);
201+
if (KeyAlgorithm.from(privateKey.getAlgorithm()) != KeyAlgorithm.XDH) {
202+
throw new IllegalArgumentException("Expected sealing key to use algorithm " + KeyAlgorithm.XDH +
203+
", but got " + privateKey.getAlgorithm());
204+
}
201205
return new VersionedKeyPair(new KeyPair(publicKey, privateKey), sealingPrivateKey.version());
202206
}
203207

node-repository/src/test/java/com/yahoo/vespa/hosted/provision/backup/SnapshotsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.yahoo.config.provision.ClusterSpec;
1010
import com.yahoo.config.provision.NodeResources;
1111
import com.yahoo.config.provision.NodeType;
12+
import com.yahoo.security.KeyFormat;
1213
import com.yahoo.security.KeyUtils;
1314
import com.yahoo.security.SealedSharedKey;
1415
import com.yahoo.vespa.hosted.provision.Node;
@@ -17,7 +18,6 @@
1718

1819
import java.security.KeyPair;
1920
import java.security.PublicKey;
20-
import java.security.interfaces.XECPrivateKey;
2121
import java.util.List;
2222

2323
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -54,8 +54,7 @@ void snapshot() {
5454
// Sealing key can be rotated independently of existing snapshots
5555
KeyPair keyPair = KeyUtils.generateX25519KeyPair();
5656
tester.secretStore().add(new Secret(Key.fromString("snapshot/sealingPrivateKey"),
57-
KeyUtils.toBase64EncodedX25519PrivateKey((XECPrivateKey) keyPair.getPrivate())
58-
.getBytes(),
57+
KeyUtils.toPem(keyPair.getPrivate(), KeyFormat.PKCS8).getBytes(),
5958
SecretVersionId.of("2")));
6059
assertEquals(SecretVersionId.of("1"), snapshots.require(snapshot0.id(), node0).key().sealingKeyVersion());
6160
assertNotEquals(snapshot0.key().sharedKey(), snapshots.keyOf(snapshot0.id(), node0, receiverPublicKey),

node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.yahoo.config.provision.Zone;
3434
import com.yahoo.config.provisioning.FlavorsConfig;
3535
import com.yahoo.jdisc.test.MockMetric;
36+
import com.yahoo.security.KeyFormat;
3637
import com.yahoo.security.KeyUtils;
3738
import com.yahoo.test.ManualClock;
3839
import com.yahoo.transaction.NestedTransaction;
@@ -69,7 +70,6 @@
6970
import com.yahoo.vespa.service.duper.TenantHostApplication;
7071

7172
import java.security.KeyPair;
72-
import java.security.interfaces.XECPrivateKey;
7373
import java.time.temporal.TemporalAmount;
7474
import java.util.ArrayList;
7575
import java.util.Collection;
@@ -772,8 +772,7 @@ private SecretStoreMock defaultSecretStore() {
772772
SecretStoreMock secretStore = new SecretStoreMock();
773773
KeyPair keyPair = KeyUtils.generateX25519KeyPair();
774774
secretStore.add(new Secret(Key.fromString("snapshot/sealingPrivateKey"),
775-
KeyUtils.toBase64EncodedX25519PrivateKey((XECPrivateKey) keyPair.getPrivate())
776-
.getBytes(),
775+
KeyUtils.toPem(keyPair.getPrivate(), KeyFormat.PKCS8).getBytes(),
777776
SecretVersionId.of("1")));
778777
return secretStore;
779778
}

node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.yahoo.config.provision.NodeType;
1212
import com.yahoo.config.provision.SystemName;
1313
import com.yahoo.config.provision.TenantName;
14+
import com.yahoo.security.KeyFormat;
1415
import com.yahoo.security.KeyUtils;
1516
import com.yahoo.slime.SlimeUtils;
1617
import com.yahoo.text.Utf8;
@@ -28,7 +29,6 @@
2829
import java.io.IOException;
2930
import java.nio.charset.StandardCharsets;
3031
import java.security.KeyPair;
31-
import java.security.interfaces.XECPrivateKey;
3232
import java.security.interfaces.XECPublicKey;
3333
import java.time.Duration;
3434
import java.util.Arrays;
@@ -876,8 +876,7 @@ public void test_snapshots() throws IOException {
876876
.getComponent(SecretStoreMock.class.getName());
877877
KeyPair keyPair = KeyUtils.generateX25519KeyPair();
878878
secretStore.add(new Secret(Key.fromString("snapshot/sealingPrivateKey"),
879-
KeyUtils.toBase64EncodedX25519PrivateKey((XECPrivateKey) keyPair.getPrivate())
880-
.getBytes(),
879+
KeyUtils.toPem(keyPair.getPrivate(), KeyFormat.PKCS8).getBytes(),
881880
SecretVersionId.of("1")));
882881

883882
// Trigger creation of snapshots

0 commit comments

Comments
 (0)