|
358 | 358 | end |
359 | 359 |
|
360 | 360 | context 'when ECDSA algorithm' do |
| 361 | + let(:root_key) { create_ecc_key(key_curve_id) } |
| 362 | + let(:attestation_key) { create_ecc_key(key_curve_id) } |
| 363 | + let(:attested_key) { create_ecc_key(key_curve_id) } |
| 364 | + let(:key_curve_id) { TPM::ECC_NIST_P256 } |
| 365 | + |
| 366 | + let(:signature_algorithm) { TPM::ALG_ECDSA } |
| 367 | + let(:hash_algorithm) { TPM::ALG_SHA256 } |
| 368 | + let(:hash_function) { "SHA256" } |
| 369 | + |
| 370 | + let(:certified_key) do |
| 371 | + t_public = TPM::TPublic.new |
| 372 | + t_public.alg_type = TPM::ALG_ECC |
| 373 | + t_public.name_alg = name_alg |
| 374 | + t_public.parameters.symmetric = TPM::ALG_NULL |
| 375 | + t_public.parameters.scheme = scheme |
| 376 | + t_public.parameters.curve_id = t_public_curve_id |
| 377 | + t_public.parameters.kdf = TPM::ALG_NULL |
| 378 | + |
| 379 | + public_key_bytes = attested_key.public_key.to_bn.to_s(2)[1..-1] |
| 380 | + coordinate_length = public_key_bytes.size / 2 |
| 381 | + t_public.unique.x.buffer = public_key_bytes[0..(coordinate_length - 1)] |
| 382 | + t_public.unique.y.buffer = public_key_bytes[coordinate_length..-1] |
| 383 | + |
| 384 | + t_public.to_binary_s |
| 385 | + end |
| 386 | + |
361 | 387 | context "when the scheme parameter from pubArea is TPM_ALG_NULL" do |
362 | | - let(:root_key) { create_ecc_key(curve_id) } |
363 | | - let(:attestation_key) { create_ecc_key(curve_id) } |
364 | | - let(:attested_key) { create_ecc_key(curve_id) } |
| 388 | + let(:scheme) { TPM::ALG_NULL } |
365 | 389 |
|
366 | | - let(:signature_algorithm) { TPM::ALG_ECDSA } |
367 | | - let(:hash_algorithm) { TPM::ALG_SHA256 } |
368 | | - let(:hash_function) { "SHA256" } |
369 | | - |
370 | | - let(:certified_key) do |
371 | | - t_public = TPM::TPublic.new |
372 | | - t_public.alg_type = TPM::ALG_ECC |
373 | | - t_public.name_alg = name_alg |
374 | | - t_public.parameters.symmetric = TPM::ALG_NULL |
375 | | - t_public.parameters.scheme = TPM::ALG_NULL |
376 | | - t_public.parameters.curve_id = curve_id |
377 | | - t_public.parameters.kdf = TPM::ALG_NULL |
378 | | - |
379 | | - public_key_bytes = attested_key.public_key.to_bn.to_s(2)[1..-1] |
380 | | - coordinate_length = public_key_bytes.size / 2 |
381 | | - t_public.unique.x.buffer = public_key_bytes[0..(coordinate_length - 1)] |
382 | | - t_public.unique.y.buffer = public_key_bytes[coordinate_length..-1] |
383 | | - |
384 | | - t_public.to_binary_s |
| 390 | + context "when t_public.parameters and t_public.unique are compatible" do |
| 391 | + let(:t_public_curve_id) { TPM::ECC_NIST_P256 } |
| 392 | + |
| 393 | + it "returns a public ECDSA key with the correct properties" do |
| 394 | + expect(key_attestation.key).to be_a(OpenSSL::PKey::EC) |
| 395 | + expect(key_attestation.key.group.curve_name).to eq("prime256v1") |
| 396 | + expect(key_attestation.key.public_key).to eq(attested_key.public_key) |
| 397 | + end |
385 | 398 | end |
386 | 399 |
|
387 | | - let(:curve_id) { TPM::ECC_NIST_P256 } |
| 400 | + context "when t_public.parameters and t_public.unique are incompatible" do |
| 401 | + # Make the curve in t_public.parameters different than the curve |
| 402 | + # used to generate the coordinates of the t_public.unique field |
| 403 | + let(:t_public_curve_id) { TPM::ECC_NIST_P384 } |
388 | 404 |
|
389 | | - it "returns a public ECDSA key with the correct properties" do |
390 | | - expect(key_attestation.key).to be_a(OpenSSL::PKey::EC) |
391 | | - expect(key_attestation.key.group.curve_name).to eq("prime256v1") |
392 | | - expect(key_attestation.key.public_key).to eq(attested_key.public_key) |
| 405 | + it "returns nil" do |
| 406 | + expect(key_attestation.key).to be nil |
| 407 | + end |
393 | 408 | end |
394 | 409 | end |
395 | 410 | end |
|
0 commit comments