Added functions: cert_open, cert_query, cert_close
SC-1140
Currently the queries for subject and hostnames are not complete and produce different results than in the c implementation.
I wrote a NASL script with an example certificate to compare results between c and rust:
cert=raw_string(0x30,0x82,0x07,0xfd,0x30,0x82,0x05,0xe5,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,0x68,0x16,0x04,0xdf,0xf3,0x34,0xf1,0x71,0xd8,0x0a,0x73,0x55,0x99,0xc1,0x41,0x72,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x0b,0x05,0x00,0x30,0x72,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x08,0x0c,0x05,0x54,0x65,0x78,0x61,0x73,0x31,0x10,0x30,0x0e,0x06,0x03,0x55,0x04,0x07,0x0c,0x07,0x48,0x6f,0x75,0x73,0x74,0x6f,0x6e,0x31,0x11,0x30,0x0f,0x06,0x03,0x55,0x04,0x0a,0x0c,0x08,0x53,0x53,0x4c,0x20,0x43,0x6f,0x72,0x70,0x31,0x2e,0x30,0x2c,0x06,0x03,0x55,0x04,0x03,0x0c,0x25,0x53,0x53,0x4c,0x2e,0x63,0x6f,0x6d,0x20,0x45,0x56,0x20,0x53,0x53,0x4c,0x20,0x49,0x6e,0x74,0x65,0x72,0x6d,0x65,0x64,0x69,0x61,0x74,0x65,0x20,0x43,0x41,0x20,0x52,0x53,0x41,0x20,0x52,0x33,0x30,0x1e,0x17,0x0d,0x32,0x30,0x30,0x34,0x30,0x31,0x30,0x30,0x35,0x38,0x33,0x33,0x5a,0x17,0x0d,0x32,0x31,0x30,0x37,0x31,0x36,0x30,0x30,0x35,0x38,0x33,0x33,0x5a,0x30,0x81,0xbd,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x08,0x0c,0x05,0x54,0x65,0x78,0x61,0x73,0x31,0x10,0x30,0x0e,0x06,0x03,0x55,0x04,0x07,0x0c,0x07,0x48,0x6f,0x75,0x73,0x74,0x6f,0x6e,0x31,0x11,0x30,0x0f,0x06,0x03,0x55,0x04,0x0a,0x0c,0x08,0x53,0x53,0x4c,0x20,0x43,0x6f,0x72,0x70,0x31,0x16,0x30,0x14,0x06,0x03,0x55,0x04,0x05,0x13,0x0d,0x4e,0x56,0x32,0x30,0x30,0x38,0x31,0x36,0x31,0x34,0x32,0x34,0x33,0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x03,0x0c,0x0b,0x77,0x77,0x77,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x31,0x1d,0x30,0x1b,0x06,0x03,0x55,0x04,0x0f,0x0c,0x14,0x50,0x72,0x69,0x76,0x61,0x74,0x65,0x20,0x4f,0x72,0x67,0x61,0x6e,0x69,0x7a,0x61,0x74,0x69,0x6f,0x6e,0x31,0x17,0x30,0x15,0x06,0x0b,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x3c,0x02,0x01,0x02,0x0c,0x06,0x4e,0x65,0x76,0x61,0x64,0x61,0x31,0x13,0x30,0x11,0x06,0x0b,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x3c,0x02,0x01,0x03,0x13,0x02,0x55,0x53,0x30,0x82,0x01,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0f,0x00,0x30,0x82,0x01,0x0a,0x02,0x82,0x01,0x01,0x00,0xc7,0x85,0xe4,0x64,0x6d,0xbd,0x45,0x09,0xce,0xf1,0x44,0xab,0x2d,0xc0,0xad,0x09,0x20,0x66,0x8a,0x63,0xcb,0x7b,0x25,0xb4,0xb6,0x6d,0x0d,0x9b,0xe9,0x82,0x09,0x0e,0x09,0xc7,0xb8,0x86,0x07,0xa8,0x1a,0xc2,0x51,0x5e,0xfd,0xa1,0xe9,0x62,0x92,0x4a,0x24,0x46,0x41,0x6f,0x72,0xfa,0x5a,0x2a,0x29,0xc5,0x1c,0x34,0x07,0x52,0x95,0x84,0x23,0xa4,0x54,0x11,0x16,0x26,0x48,0x28,0x37,0x3b,0xc5,0xa2,0xe3,0x6b,0x8e,0x71,0x5d,0x81,0xe5,0x96,0x9b,0x99,0x70,0xa4,0xc1,0xdc,0x58,0xe4,0x47,0x25,0xe7,0x50,0x5b,0x33,0xc5,0x27,0x19,0xda,0x00,0x19,0xb7,0x4d,0x9a,0x24,0x66,0x4a,0x64,0xe3,0x72,0xcf,0xa5,0x84,0xcc,0x60,0xe1,0xf1,0x58,0xea,0x50,0x69,0x88,0x45,0x45,0x88,0x65,0x23,0x19,0x14,0x7e,0xeb,0x54,0x7a,0xec,0xbc,0xfa,0x53,0x82,0x89,0x78,0xb3,0x5c,0x0a,0x6d,0x3b,0x43,0x01,0x58,0x28,0x19,0xa9,0x8b,0x4f,0x20,0x77,0x28,0x12,0xbd,0x17,0x54,0xc3,0x9e,0x49,0xa2,0x9a,0xde,0x76,0x3f,0x95,0x1a,0xd8,0xd4,0x90,0x1e,0x21,0x15,0x3e,0x06,0x41,0x7f,0xe0,0x86,0xde,0xbd,0x46,0x5a,0xb3,0xff,0xef,0x2e,0xd1,0xd1,0x10,0x92,0x1b,0x94,0xba,0xe7,0x2b,0xa9,0xa9,0x66,0x48,0x6c,0xb8,0xdc,0x74,0x70,0x05,0xf0,0xca,0x17,0x06,0x1e,0x58,0xce,0xc2,0x3c,0xc7,0x79,0x7b,0xf7,0x4e,0xfa,0xdd,0x3c,0xb7,0xc3,0xdb,0x8f,0x35,0x53,0x4e,0xfe,0x61,0x40,0x30,0xac,0x11,0x82,0x15,0xd9,0x3e,0xc0,0x14,0x8f,0x52,0x70,0xdc,0x4c,0x92,0x1e,0xff,0x02,0x03,0x01,0x00,0x01,0xa3,0x82,0x03,0x41,0x30,0x82,0x03,0x3d,0x30,0x1f,0x06,0x03,0x55,0x1d,0x23,0x04,0x18,0x30,0x16,0x80,0x14,0xbf,0xc1,0x5a,0x87,0xff,0x28,0xfa,0x41,0x3d,0xfd,0xb7,0x4f,0xe4,0x1d,0xaf,0xa0,0x61,0x58,0x29,0xbd,0x30,0x7f,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x01,0x01,0x04,0x73,0x30,0x71,0x30,0x4d,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x30,0x02,0x86,0x41,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x77,0x77,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x2f,0x72,0x65,0x70,0x6f,0x73,0x69,0x74,0x6f,0x72,0x79,0x2f,0x53,0x53,0x4c,0x63,0x6f,0x6d,0x2d,0x53,0x75,0x62,0x43,0x41,0x2d,0x45,0x56,0x2d,0x53,0x53,0x4c,0x2d,0x52,0x53,0x41,0x2d,0x34,0x30,0x39,0x36,0x2d,0x52,0x33,0x2e,0x63,0x72,0x74,0x30,0x20,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x86,0x14,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x6f,0x63,0x73,0x70,0x73,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x30,0x1f,0x06,0x03,0x55,0x1d,0x11,0x04,0x18,0x30,0x16,0x82,0x0b,0x77,0x77,0x77,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x82,0x07,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x30,0x5f,0x06,0x03,0x55,0x1d,0x20,0x04,0x58,0x30,0x56,0x30,0x07,0x06,0x05,0x67,0x81,0x0c,0x01,0x01,0x30,0x0d,0x06,0x0b,0x2a,0x84,0x68,0x01,0x86,0xf6,0x77,0x02,0x05,0x01,0x01,0x30,0x3c,0x06,0x0c,0x2b,0x06,0x01,0x04,0x01,0x82,0xa9,0x30,0x01,0x03,0x01,0x04,0x30,0x2c,0x30,0x2a,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x02,0x01,0x16,0x1e,0x68,0x74,0x74,0x70,0x73,0x3a,0x2f,0x2f,0x77,0x77,0x77,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x2f,0x72,0x65,0x70,0x6f,0x73,0x69,0x74,0x6f,0x72,0x79,0x30,0x1d,0x06,0x03,0x55,0x1d,0x25,0x04,0x16,0x30,0x14,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x03,0x02,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x03,0x01,0x30,0x48,0x06,0x03,0x55,0x1d,0x1f,0x04,0x41,0x30,0x3f,0x30,0x3d,0xa0,0x3b,0xa0,0x39,0x86,0x37,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x63,0x72,0x6c,0x73,0x2e,0x73,0x73,0x6c,0x2e,0x63,0x6f,0x6d,0x2f,0x53,0x53,0x4c,0x63,0x6f,0x6d,0x2d,0x53,0x75,0x62,0x43,0x41,0x2d,0x45,0x56,0x2d,0x53,0x53,0x4c,0x2d,0x52,0x53,0x41,0x2d,0x34,0x30,0x39,0x36,0x2d,0x52,0x33,0x2e,0x63,0x72,0x6c,0x30,0x1d,0x06,0x03,0x55,0x1d,0x0e,0x04,0x16,0x04,0x14,0x00,0xc0,0x15,0x42,0x1a,0xcf,0x0e,0x6b,0x64,0x81,0xda,0xa6,0x74,0x71,0x21,0x49,0xe9,0xc3,0xe1,0x8b,0x30,0x0e,0x06,0x03,0x55,0x1d,0x0f,0x01,0x01,0xff,0x04,0x04,0x03,0x02,0x05,0xa0,0x30,0x82,0x01,0x7d,0x06,0x0a,0x2b,0x06,0x01,0x04,0x01,0xd6,0x79,0x02,0x04,0x02,0x04,0x82,0x01,0x6d,0x04,0x82,0x01,0x69,0x01,0x67,0x00,0x77,0x00,0xf6,0x5c,0x94,0x2f,0xd1,0x77,0x30,0x22,0x14,0x54,0x18,0x08,0x30,0x94,0x56,0x8e,0xe3,0x4d,0x13,0x19,0x33,0xbf,0xdf,0x0c,0x2f,0x20,0x0b,0xcc,0x4e,0xf1,0x64,0xe3,0x00,0x00,0x01,0x71,0x33,0x48,0x68,0x6f,0x00,0x00,0x04,0x03,0x00,0x48,0x30,0x46,0x02,0x21,0x00,0xeb,0x17,0xa5,0x88,0xd4,0x7c,0x1a,0x4f,0xfa,0xde,0x96,0x1d,0x9d,0x2f,0xef,0x3b,0x1f,0xc2,0x8e,0x9b,0x44,0x30,0x4b,0xfc,0xf5,0x65,0xa1,0xd7,0xfb,0xab,0x58,0x81,0x02,0x21,0x00,0xf2,0x06,0xb7,0x87,0x53,0x6e,0x43,0xcf,0x0b,0xa4,0x41,0xa4,0x50,0x8f,0x05,0xba,0xe7,0x96,0x4b,0x92,0xa0,0xa7,0xc5,0xbc,0x50,0x59,0x18,0x8e,0x7a,0x68,0xfd,0x24,0x00,0x75,0x00,0x94,0x20,0xbc,0x1e,0x8e,0xd5,0x8d,0x6c,0x88,0x73,0x1f,0x82,0x8b,0x22,0x2c,0x0d,0xd1,0xda,0x4d,0x5e,0x6c,0x4f,0x94,0x3d,0x61,0xdb,0x4e,0x2f,0x58,0x4d,0xa2,0xc2,0x00,0x00,0x01,0x71,0x33,0x48,0x68,0xdc,0x00,0x00,0x04,0x03,0x00,0x46,0x30,0x44,0x02,0x20,0x19,0x11,0x38,0xc3,0x36,0x9b,0x35,0x17,0x43,0xf2,0x4a,0xbf,0xbc,0x53,0xf7,0xb5,0x07,0xb6,0x86,0x6d,0x31,0xe6,0x75,0xee,0x96,0x8c,0x21,0xe0,0x86,0xf0,0xde,0x59,0x02,0x20,0x56,0x1b,0xff,0x79,0x52,0x0e,0x99,0x52,0xec,0x07,0x11,0xe2,0xbf,0x97,0xa5,0x6b,0x44,0x29,0x24,0xc5,0x58,0x99,0x8d,0x09,0x16,0xdc,0x5c,0x9b,0xab,0xd9,0x11,0x81,0x00,0x75,0x00,0xee,0xc0,0x95,0xee,0x8d,0x72,0x64,0x0f,0x92,0xe3,0xc3,0xb9,0x1b,0xc7,0x12,0xa3,0x69,0x6a,0x09,0x7b,0x4b,0x6a,0x1a,0x14,0x38,0xe6,0x47,0xb2,0xcb,0xed,0xc5,0xf9,0x00,0x00,0x01,0x71,0x33,0x48,0x68,0xf3,0x00,0x00,0x04,0x03,0x00,0x46,0x30,0x44,0x02,0x20,0x7a,0x22,0xf6,0xe8,0x5a,0xcb,0x37,0x47,0x82,0x2d,0x57,0x08,0xde,0x6e,0x5e,0xc3,0xdf,0x2a,0x05,0x69,0x7d,0x0d,0x0e,0x1d,0x9d,0x5a,0x18,0x60,0xc0,0x2c,0x6b,0x1f,0x02,0x20,0x09,0xfa,0xbb,0xa1,0xc3,0x02,0xe6,0xdf,0xb5,0x8e,0x2e,0x4c,0xe7,0x16,0x8b,0x98,0xf0,0xb8,0x23,0xe5,0x97,0xdc,0x8f,0xc0,0x46,0x45,0x92,0xca,0x23,0xbb,0x21,0x07,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x0b,0x05,0x00,0x03,0x82,0x02,0x01,0x00,0x27,0xae,0xba,0xbe,0x10,0x9e,0xe8,0xea,0x9a,0x0b,0x92,0xac,0x75,0x37,0x9a,0x17,0xfe,0x70,0x9a,0x1d,0xcd,0x34,0x0d,0xaa,0x8e,0x2d,0x75,0xef,0x8f,0x0f,0x5f,0xde,0x15,0xd6,0x00,0x10,0xbb,0xbc,0xc4,0x5f,0xb4,0x02,0xde,0xf1,0x26,0x23,0xd8,0x8b,0x94,0x4a,0xc2,0x29,0x72,0x3f,0x9e,0xaf,0xfb,0x78,0x98,0xd9,0x3f,0x65,0xc3,0xb4,0xbc,0x4c,0x9d,0x38,0xd5,0x52,0xe1,0x68,0x82,0xa9,0xd7,0x83,0x33,0x49,0x4c,0xd1,0xc9,0xea,0x0e,0x02,0xc2,0x7b,0x40,0x00,0xcc,0x0a,0x51,0xca,0x50,0x39,0x47,0x51,0x4d,0xa9,0x36,0xea,0x3c,0xf1,0x8e,0xa2,0x82,0x8b,0xd3,0xdd,0xbb,0x27,0xc0,0x93,0x62,0x11,0x03,0x6a,0xca,0x64,0x92,0x62,0x19,0x2d,0xc3,0x4b,0x5a,0x76,0xea,0x2a,0x8e,0xa5,0xe7,0xd3,0xa8,0x2c,0x56,0x2a,0x16,0x4d,0x50,0xd7,0xca,0xc7,0x79,0xa8,0x4c,0x78,0xb7,0xab,0x08,0x80,0x87,0x0c,0x9b,0x6e,0x98,0x1f,0x5b,0xc9,0xa4,0x24,0x04,0x84,0xaa,0x5c,0xdb,0x2d,0x3b,0x81,0x19,0x24,0x94,0x16,0x51,0xb4,0xc8,0xd3,0x86,0xfe,0x1c,0x5f,0x2c,0x8c,0x5f,0xbb,0x93,0x71,0xd4,0xfb,0x00,0x90,0x4f,0xb9,0xe8,0x9f,0x0a,0x85,0x76,0xe4,0x9c,0x57,0xba,0x8f,0x1d,0xe7,0x5d,0xfd,0x83,0x03,0xf5,0x04,0x07,0xbb,0x20,0x15,0x4f,0xc7,0x6b,0xbb,0x28,0xdf,0xd4,0xc8,0xe5,0xdd,0x66,0x6c,0x0c,0x7f,0xf4,0xe6,0x14,0x6c,0x03,0x74,0x27,0xec,0xc8,0x77,0xff,0x66,0xc0,0x76,0xc0,0xb1,0xe8,0xcd,0x36,0x28,0x01,0x59,0x90,0xf4,0x5a,0x14,0xd4,0x92,0xe0,0x71,0x58,0xaf,0xa8,0x9f,0xaf,0x36,0x50,0x61,0x1d,0x78,0x65,0xc4,0xc7,0x4d,0xd2,0x3f,0x34,0x47,0xd3,0x73,0xe8,0x42,0x20,0x95,0x08,0xde,0x2b,0x73,0xbc,0x23,0xf7,0x05,0x1a,0x6f,0xc1,0xf3,0xee,0x36,0x84,0xe9,0x42,0x21,0xdf,0x59,0x76,0xd9,0xdd,0x25,0xc4,0x49,0x56,0x38,0xb4,0xc0,0x3d,0x2a,0xc1,0xeb,0xc2,0x69,0xf0,0x3d,0x8c,0x99,0x47,0xbf,0xf8,0xec,0x13,0xe2,0x3d,0x53,0x3e,0x9c,0xa4,0x2c,0xa1,0xb3,0x0f,0xa5,0xac,0x57,0x71,0x52,0x0a,0x94,0xe7,0xc6,0xb1,0xa9,0xe2,0xbc,0xf4,0x54,0x7e,0x36,0x8e,0x2a,0xd0,0x82,0x0e,0xf8,0x98,0xb5,0xac,0x92,0xab,0xf6,0x79,0x12,0x07,0x40,0x6a,0x5e,0x8c,0xd5,0x9c,0x4d,0x58,0x07,0xf2,0x8b,0xbd,0xd2,0x2c,0xb9,0x86,0x49,0xba,0xa6,0xf6,0xa4,0xa9,0x2e,0xfb,0x3c,0xd3,0xea,0x05,0x30,0x1d,0x44,0xd9,0xbc,0x18,0x8d,0x3a,0xd5,0xcb,0xe0,0xdc,0x70,0x73,0xf2,0x93,0xed,0x6c,0xce,0x49,0xdd,0xb0,0x3f,0x5d,0x10,0x23,0xc0,0xca,0x83,0x8b,0xdf,0x88,0xd0,0xec,0x1d,0x69,0x81,0xd5,0xce,0x0a,0x8e,0x2e,0xa0,0x3a,0x00,0x39,0xb9,0x25,0x33,0x68,0x69,0xaa,0xfe,0xfe,0x15,0x9d,0xc2,0xb9,0x52,0xbf,0xa7,0xf4,0xb6,0xdf,0x9d,0xf2,0xdc,0xdb,0xc2,0x79,0x7e,0xdf,0xc6,0xa2,0xd8,0xa7,0x33,0x20,0xe4,0xde,0x26,0xab,0x17,0x5d,0x18,0x96,0xa7,0x0e,0x99,0xe5,0xf5,0xb8,0x59,0x8a,0x6d,0xd8,0xbf,0x5e,0x8a,0xc6,0x96,0x40,0xa8,0x30,0x5d,0xd3,0x0f,0x1f,0x2b,0x9a,0x9f,0x43,0x06,0x20,0x7f);
id=cert_open(cert);
display(cert_query(id,"subject"));
cert_close(id);
~~Currently the following query commands do not work like in the c implementation:~~
- ~~subject~~
- ~~hostnames~~
~~The issue here is, that the library I used does not contain the Subject Alternative Name extension.~~
~~I also checked for other libraries handling certificates (rustls and x509-parser), but they all come with their drawbacks. Maybe the best solution would be to combine two of these libraries?~~
All query parameters are now implemented.