Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/channels/rdpear/common/rdpear_asn1.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * ASN1 routines for RDPEAR
4
 *
5
 * Copyright 2024 David Fort <contact@hardening-consulting.com>
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
20
#include <rdpear-common/rdpear_asn1.h>
21
#include <winpr/asn1.h>
22
23
wStream* rdpear_enc_Checksum(UINT32 cksumtype, krb5_checksum* csum)
24
0
{
25
  /**
26
   * Checksum        ::= SEQUENCE {
27
   *   cksumtype       [0] Int32,
28
   *   checksum        [1] OCTET STRING
29
   * }
30
   */
31
0
  wStream* ret = NULL;
32
0
  WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
33
0
  if (!enc)
34
0
    return NULL;
35
36
0
  if (!WinPrAsn1EncSeqContainer(enc))
37
0
    goto out;
38
39
0
  if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)cksumtype))
40
0
    goto out;
41
42
0
  WinPrAsn1_OctetString octets;
43
0
  octets.data = (BYTE*)csum->contents;
44
0
  octets.len = csum->length;
45
0
  if (!WinPrAsn1EncContextualOctetString(enc, 1, &octets) || !WinPrAsn1EncEndContainer(enc))
46
0
    goto out;
47
48
0
  ret = Stream_New(NULL, 1024);
49
0
  if (!ret)
50
0
    goto out;
51
52
0
  if (!WinPrAsn1EncToStream(enc, ret))
53
0
  {
54
0
    Stream_Free(ret, TRUE);
55
0
    ret = NULL;
56
0
    goto out;
57
0
  }
58
59
0
out:
60
0
  WinPrAsn1Encoder_Free(&enc);
61
0
  return ret;
62
0
}
63
64
wStream* rdpear_enc_EncryptedData(UINT32 encType, krb5_data* payload)
65
0
{
66
  /**
67
   * EncryptedData   ::= SEQUENCE {
68
   *   etype   [0] Int32 -- EncryptionType --,
69
   *   kvno    [1] UInt32 OPTIONAL,
70
   *   cipher  [2] OCTET STRING -- ciphertext
71
   *  }
72
   */
73
0
  wStream* ret = NULL;
74
0
  WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
75
0
  if (!enc)
76
0
    return NULL;
77
78
0
  if (!WinPrAsn1EncSeqContainer(enc))
79
0
    goto out;
80
81
0
  if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)encType))
82
0
    goto out;
83
84
0
  WinPrAsn1_OctetString octets;
85
0
  octets.data = (BYTE*)payload->data;
86
0
  octets.len = payload->length;
87
0
  if (!WinPrAsn1EncContextualOctetString(enc, 2, &octets) || !WinPrAsn1EncEndContainer(enc))
88
0
    goto out;
89
90
0
  ret = Stream_New(NULL, 1024);
91
0
  if (!ret)
92
0
    goto out;
93
94
0
  if (!WinPrAsn1EncToStream(enc, ret))
95
0
  {
96
0
    Stream_Free(ret, TRUE);
97
0
    ret = NULL;
98
0
    goto out;
99
0
  }
100
101
0
out:
102
0
  WinPrAsn1Encoder_Free(&enc);
103
0
  return ret;
104
0
}