FreeRDP
rdpear_asn1.c
1 
20 #include <rdpear-common/rdpear_asn1.h>
21 #include <winpr/asn1.h>
22 
23 wStream* rdpear_enc_Checksum(UINT32 cksumtype, krb5_checksum* csum)
24 {
31  wStream* ret = NULL;
32  WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
33  if (!enc)
34  return NULL;
35 
36  if (!WinPrAsn1EncSeqContainer(enc))
37  goto out;
38 
39  if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)cksumtype))
40  goto out;
41 
42  WinPrAsn1_OctetString octets;
43  octets.data = (BYTE*)csum->contents;
44  octets.len = csum->length;
45  if (!WinPrAsn1EncContextualOctetString(enc, 1, &octets) || !WinPrAsn1EncEndContainer(enc))
46  goto out;
47 
48  ret = Stream_New(NULL, 1024);
49  if (!ret)
50  goto out;
51 
52  if (!WinPrAsn1EncToStream(enc, ret))
53  {
54  Stream_Free(ret, TRUE);
55  ret = NULL;
56  goto out;
57  }
58 
59 out:
60  WinPrAsn1Encoder_Free(&enc);
61  return ret;
62 }
63 
64 wStream* rdpear_enc_EncryptedData(UINT32 encType, krb5_data* payload)
65 {
73  wStream* ret = NULL;
74  WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
75  if (!enc)
76  return NULL;
77 
78  if (!WinPrAsn1EncSeqContainer(enc))
79  goto out;
80 
81  if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)encType))
82  goto out;
83 
84  WinPrAsn1_OctetString octets;
85  octets.data = (BYTE*)payload->data;
86  octets.len = payload->length;
87  if (!WinPrAsn1EncContextualOctetString(enc, 2, &octets) || !WinPrAsn1EncEndContainer(enc))
88  goto out;
89 
90  ret = Stream_New(NULL, 1024);
91  if (!ret)
92  goto out;
93 
94  if (!WinPrAsn1EncToStream(enc, ret))
95  {
96  Stream_Free(ret, TRUE);
97  ret = NULL;
98  goto out;
99  }
100 
101 out:
102  WinPrAsn1Encoder_Free(&enc);
103  return ret;
104 }