Skip to content

Commit

Permalink
Merge "Fix Lint errors and comment on how integration test keysets we…
Browse files Browse the repository at this point in the history
…re generated."

ORIGINAL_AUTHOR=Thai Duong <[email protected]>
GitOrigin-RevId: 91140a0c46a82b88649f07a744db27d796870113
  • Loading branch information
thaidn committed May 12, 2017
1 parent 1c534b4 commit 7b7c6b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
import com.google.protobuf.ByteString;
import java.security.GeneralSecurityException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,20 @@ public void testExtractPublicKey() throws Exception {
@Test
public void testWithTinkeyEciesAesGcmHkdf() throws Exception {
// Generated with
// tinkey create --key-type EciesAeadHkdf
// --key-format "params { kem_params { curve_type: NIST_P256 hkdf_hash_type: SHA256}
// dem_params { aead_dem {type_url: \"type.googleapis.com/google.cloud.crypto.tink.AesGcmKey\"
// value: \"\020\020\"} } ec_point_format: UNCOMPRESSED}" --out ../private_key.cfg
final String PRIVATE_KEYSET =
// tinkey create \
// --key-template ECIES_P256_HKDFHMACSHA256_AES128GCM.proto \
// --out private_key.cfg
final String privateKeyset =
"CKqtvK8HEo0CCoACCkR0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5j"
+ "cnlwdG8udGluay5FY2llc0FlYWRIa2RmUHJpdmF0ZUtleRK1ARKQARJICgQIAhAD"
+ "Ej4SPAo2dHlwZS5nb29nbGVhcGlzLmNvbS9nb29nbGUuY2xvdWQuY3J5cHRvLnRp"
+ "bmsuQWVzR2NtS2V5EgIQEBgBGiEAshFW965cYU3B6wwQ9OnqiICPoccQk1J7s19e"
+ "AR1PZk0iIQDQZRrtrcrj+PH7cGAiXjAtG/jLPYC46AQFOuZAfuitqxogWbIJkYNY"
+ "WiJ7D4NMku5zLgH5e6Fcy5vXEuYeHSbgvPQYAhABGKqtvK8HIAE=";


// Generated with
// tinkey create-public-keyset --in ../private_key.cfg --out ../public_key.cfg
final String PUBLIC_KEYSET =
// tinkey create-public-keyset --in private_key.cfg --out public_key.cfg
final String publicKeyset =
"CKqtvK8HEucBCtoBCkN0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5j"
+ "cnlwdG8udGluay5FY2llc0FlYWRIa2RmUHVibGljS2V5EpABEkgKBAgCEAMSPhI8"
+ "CjZ0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5jcnlwdG8udGluay5B"
Expand All @@ -122,10 +120,10 @@ public void testWithTinkeyEciesAesGcmHkdf() throws Exception {


HybridDecrypt hybridDecrypt = HybridDecryptFactory.getPrimitive(
CleartextKeysetHandle.parseFrom(base64().decode(PRIVATE_KEYSET)));
CleartextKeysetHandle.parseFrom(base64().decode(privateKeyset)));

HybridEncrypt hybridEncrypt = HybridEncryptFactory.getPrimitive(
CleartextKeysetHandle.parseFrom(base64().decode(PUBLIC_KEYSET)));
CleartextKeysetHandle.parseFrom(base64().decode(publicKeyset)));

byte[] plaintext = Random.randBytes(20);
byte[] contextInfo = Random.randBytes(20);
Expand All @@ -138,7 +136,10 @@ public void testWithTinkeyEciesAesGcmHkdf() throws Exception {
*/
@Test
public void testWithTinkeyEciesAesCtrHmacAead() throws Exception {
final String PRIVATE_KEYSET =
// tinkey create \
// --key-template ECIES_P256_HKDFHMACSHA256_AES256CTR_128BITIV_HMACSHA256_256BITTAG.proto \
// --out private_key.cfg
final String privateKeyset =
"CJG2oOEFEqUCCpgCCkR0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5j"
+ "cnlwdG8udGluay5FY2llc0FlYWRIa2RmUHJpdmF0ZUtleRLNARKoARJgCgQIAhAD"
+ "ElYSVAo+dHlwZS5nb29nbGVhcGlzLmNvbS9nb29nbGUuY2xvdWQuY3J5cHRvLnRp"
Expand All @@ -147,7 +148,7 @@ public void testWithTinkeyEciesAesCtrHmacAead() throws Exception {
+ "Y0Ns0WkLRX3wo6IAEszPahogWYL4SpaHlwYZaBYNVTibJueOdaPbeaLHiyCVBAkn"
+ "YAwYAhABGJG2oOEFIAE=";

final String PUBLIC_KEYSET =
final String publicKeyset =
"CJG2oOEFEv8BCvIBCkN0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5j"
+ "cnlwdG8udGluay5FY2llc0FlYWRIa2RmUHVibGljS2V5EqgBEmAKBAgCEAMSVhJU"
+ "Cj50eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jbG91ZC5jcnlwdG8udGluay5B"
Expand All @@ -157,10 +158,10 @@ public void testWithTinkeyEciesAesCtrHmacAead() throws Exception {


HybridDecrypt hybridDecrypt = HybridDecryptFactory.getPrimitive(
CleartextKeysetHandle.parseFrom(base64().decode(PRIVATE_KEYSET)));
CleartextKeysetHandle.parseFrom(base64().decode(privateKeyset)));

HybridEncrypt hybridEncrypt = HybridEncryptFactory.getPrimitive(
CleartextKeysetHandle.parseFrom(base64().decode(PUBLIC_KEYSET)));
CleartextKeysetHandle.parseFrom(base64().decode(publicKeyset)));

byte[] plaintext = Random.randBytes(20);
byte[] contextInfo = Random.randBytes(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import com.google.cloud.crypto.tink.TinkProto.KeysetInfo;
import com.google.cloud.crypto.tink.TinkProto.OutputPrefixType;
import com.google.cloud.crypto.tink.aead.AeadFactory;
import com.google.cloud.crypto.tink.mac.MacFactory;
import com.google.cloud.crypto.tink.hybrid.HybridDecryptFactory;
import com.google.cloud.crypto.tink.hybrid.HybridEncryptFactory;
import com.google.cloud.crypto.tink.mac.MacFactory;
import com.google.cloud.crypto.tink.subtle.Random;
import java.security.GeneralSecurityException;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.cloudkms.v1.CloudKMS;
import com.google.api.services.cloudkms.v1.CloudKMSScopes;
import com.google.cloud.crypto.tink.GcpKmsProto.GcpKmsAeadKey;
import com.google.cloud.crypto.tink.CleartextKeysetHandle;
import com.google.cloud.crypto.tink.GcpKmsProto.GcpKmsAeadKey;
import com.google.cloud.crypto.tink.KeysetHandle;
import com.google.cloud.crypto.tink.KmsEncryptedKeysetHandle;
import com.google.cloud.crypto.tink.Registry;
import com.google.cloud.crypto.tink.TinkProto.KeyData;
import com.google.cloud.crypto.tink.TinkProto.KeyTemplate;
Expand All @@ -43,7 +42,6 @@
import com.google.protobuf.TextFormat;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,18 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.cloud.crypto.tink.AesGcmProto.AesGcmKey;
import com.google.cloud.crypto.tink.CleartextKeysetHandle;
import com.google.cloud.crypto.tink.CommonProto.EcPointFormat;
import com.google.cloud.crypto.tink.CommonProto.EllipticCurveType;
import com.google.cloud.crypto.tink.CommonProto.HashType;
import com.google.cloud.crypto.tink.EciesAeadHkdfProto.EciesAeadHkdfPrivateKey;
import com.google.cloud.crypto.tink.GcpKmsProto.GcpKmsAeadKey;
import com.google.cloud.crypto.tink.KeysetHandle;
import com.google.cloud.crypto.tink.KmsEncryptedKeysetHandle;
import com.google.cloud.crypto.tink.Registry;
import com.google.cloud.crypto.tink.TestUtil;
import com.google.cloud.crypto.tink.TinkProto.KeyData;
import com.google.cloud.crypto.tink.TinkProto.KeyStatusType;
import com.google.cloud.crypto.tink.TinkProto.KeyTemplate;
import com.google.cloud.crypto.tink.TinkProto.Keyset;
import com.google.cloud.crypto.tink.TinkProto.KeysetInfo;
import com.google.cloud.crypto.tink.TinkProto.KmsEncryptedKeyset;
import com.google.cloud.crypto.tink.TinkProto.OutputPrefixType;
import com.google.cloud.crypto.tink.aead.AeadFactory;
import com.google.cloud.crypto.tink.aead.GcpKmsAeadKeyManager;
Expand Down

0 comments on commit 7b7c6b2

Please sign in to comment.