From 18570636732daed72776d139a09ae80c905ccb41 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 15 May 2024 15:01:18 +0300 Subject: [PATCH] parse private key elements as an array --- .../service/api/handlers/create_identity.go | 16 +++++++- resources/document_sod.go | 40 +++---------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/internal/service/api/handlers/create_identity.go b/internal/service/api/handlers/create_identity.go index def174f..1837caa 100644 --- a/internal/service/api/handlers/create_identity.go +++ b/internal/service/api/handlers/create_identity.go @@ -129,7 +129,21 @@ func CreateIdentity(w http.ResponseWriter, r *http.Request) { return } - if err := validatePubSignals(cfg, req.Data, encapsulatedData.PrivateKey.El1.OctetStr.Bytes); err != nil { + privateKey := make([]asn1.RawValue, 0) + if _, err = asn1.Unmarshal(encapsulatedData.PrivateKey.FullBytes, &privateKey); err != nil { + Log(r).WithError(err).Error("failed to unmarshal ASN.1") + ape.RenderErr(w, problems.InternalError()) + return + } + + privKeyEl := resources.PrivateKeyElement{} + if _, err = asn1.Unmarshal(privateKey[0].FullBytes, &privKeyEl); err != nil { + Log(r).WithError(err).Error("failed to unmarshal ASN.1") + ape.RenderErr(w, problems.InternalError()) + return + } + + if err := validatePubSignals(cfg, req.Data, privKeyEl.OctetStr.Bytes); err != nil { Log(r).WithError(err).Error("failed to validate pub signals") ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/resources/document_sod.go b/resources/document_sod.go index d02423d..aa0a6f1 100644 --- a/resources/document_sod.go +++ b/resources/document_sod.go @@ -10,38 +10,10 @@ type DigestAttribute struct { type EncapsulatedData struct { Version int PrivateKeyAlgorithm asn1.RawValue - PrivateKey struct { - El1 struct { - Integer int - OctetStr asn1.RawValue - } - El2 struct { - Integer int - OctetStr asn1.RawValue - } - El3 struct { - Integer int - OctetStr asn1.RawValue - } - El4 struct { - Integer int - OctetStr asn1.RawValue - } - El5 struct { - Integer int - OctetStr asn1.RawValue - } - El6 struct { - Integer int - OctetStr asn1.RawValue - } - El7 struct { - Integer int - OctetStr asn1.RawValue - } - El8 struct { - Integer int - OctetStr asn1.RawValue - } - } + PrivateKey asn1.RawValue +} + +type PrivateKeyElement struct { + Integer int + OctetStr asn1.RawValue }