crypto: Improve PER OID calculations
authorOndrej Holy <oholy@redhat.com>
Tue, 19 Dec 2017 13:42:06 +0000 (14:42 +0100)
committerOndrej Holy <oholy@redhat.com>
Tue, 19 Dec 2017 13:42:06 +0000 (14:42 +0100)
"(oid[0] << 4) & (oid[1] & 0x0F)" statement is always 0. It is not
problem currently because the only OID which is written by this
function should have 0 there. The function to read/write are pretty
limited anyway and can't work properly with all kind of OIDs. Maybe
it would be better to hardcode the OID there without decoding
and encoding. But those functions are already there so let's improve
them a bit according the spec and warn about limited set of
supported OIDs.

See:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb540809

libfreerdp/crypto/per.c

index 6a7bbf8..41f0ea8 100644 (file)
@@ -309,6 +309,7 @@ void per_write_enumerated(wStream* s, BYTE enumerated, BYTE count)
  * Read PER OBJECT_IDENTIFIER (OID).
  * @param s stream
  * @param oid object identifier (OID)
+ * @warning It works correctly only for limited set of OIDs.
  * @return
  */
 
@@ -328,8 +329,8 @@ BOOL per_read_object_identifier(wStream* s, BYTE oid[6])
                return FALSE;
 
        Stream_Read_UINT8(s, t12); /* first two tuples */
-       a_oid[0] = (t12 >> 4);
-       a_oid[1] = (t12 & 0x0F);
+       a_oid[0] = t12 / 40;
+       a_oid[1] = t12 % 40;
 
        Stream_Read_UINT8(s, a_oid[2]); /* tuple 3 */
        Stream_Read_UINT8(s, a_oid[3]); /* tuple 4 */
@@ -352,11 +353,12 @@ BOOL per_read_object_identifier(wStream* s, BYTE oid[6])
  * Write PER OBJECT_IDENTIFIER (OID)
  * @param s stream
  * @param oid object identifier (oid)
+ * @warning It works correctly only for limited set of OIDs.
  */
 
 void per_write_object_identifier(wStream* s, BYTE oid[6])
 {
-       BYTE t12 = (oid[0] << 4) & (oid[1] & 0x0F);
+       BYTE t12 = oid[0] * 40 + oid[1];
        Stream_Write_UINT8(s, 5); /* length */
        Stream_Write_UINT8(s, t12); /* first two tuples */
        Stream_Write_UINT8(s, oid[2]); /* tuple 3 */