dounanyin3179 2016-09-21 06:45
浏览 74
已采纳

用于唯一标识证书的正则表达式

I am trying to come up with regex that matches the value of "Key Container", but only if the issuer is CN=My_root_CA and the certificate is Non-root Certificate All of the above should be fulfil to match the certificate uniquely, because there are several similar certificates

       ================ Certificate 3 ================
   Serial Number: 5471f66c066334ab48285398b0f24b7e
   Issuer: CN=My_Root_CA, O=Experian, OU=Hunter, L=Sofia, S=CA, C=BG
    NotBefore: 20/09/2016 15:48
    NotAfter: 20/09/2024 15:48
   Subject: CN=192.168.127.107
   Non-root Certificate
   Cert Hash(sha1): 46 92 41 60 56 36 32 fa bb 82 f2 45 0b 80 37 c4 28 15 e4 ca
     Key Container = 52668461-19b4-4fef-80d6-5982ff702c3b
     Unique container name: 0893f8f220ed765fabe249818ff664b9_bba0a089-1c2b-49c8-9f49-e4b211a91a55
     Provider = Microsoft Strong Cryptographic Provider
   Encryption test passed

I have tried this CN=My_Root_CA((.| )*?)Non-root Certificate((.| )*?)Key Container =(.*\b)

But this do not matches correctly if we have

  ================ Certificate 1 ================
   Serial Number: b4b81124ff17b6af4eb18053cd9fecd5
   Issuer: CN=My_Root_CA, O=Experian, OU=Hunter, L=Sofia, S=CA, C=BG
    NotBefore: 20/09/2016 15:48
    NotAfter: 20/09/2024 15:48
   Subject: CN=My_Root_CA, O=Experian, OU=Hunter, L=Sofia, S=CA, C=BG
   Signature matches Public Key
   Root Certificate: Subject matches Issuer
   Cert Hash(sha1): 8c 47 dd 5a 74 47 3a 74 e1 2a c4 de 6f 95 35 04 f6 2d d4 8a
     Key Container = 25ea8612-7fd3-4504-97f8-d9150e6bfd63
     Unique container name: 4e3f7aa1fb469fd4cb7b184d188059be_bba0a089-1c2b-49c8-9f49-e4b211a91a55
     Provider = Microsoft Strong Cryptographic Provider
   Encryption test passed

   ================ Certificate 2 ================
   Serial Number: XXXXXXXX
   Issuer: CN=TEST TEST FIND Root
    NotBefore: 18/08/2015 16:16
    NotAfter: 18/09/2017 16:26
   Subject: CN=TEST CA
   CA Version: V9.0
   Certificate Template Name (Certificate Type): SubCA
   Non-root Certificate
   Template: SubCA
   Cert Hash(sha1): 55 1b 22 8c c9 eb 25 58 25 3f 00 67 a3 6e 68 b1 62 43 de 75
   No key provider information
   Cannot find the certificate and private key for decryption.
   Encryption test passed

   ================ Certificate 3 ================
   Serial Number: 5471f66c066334ab48285398b0f24b7e
   Issuer: CN=My_Root_CA, O=Experian, OU=Hunter, L=Sofia, S=CA, C=BG
    NotBefore: 20/09/2016 15:48
    NotAfter: 20/09/2024 15:48
   Subject: CN=192.168.127.107
   Non-root Certificate
   Cert Hash(sha1): 46 92 41 60 56 36 32 fa bb 82 f2 45 0b 80 37 c4 28 15 e4 ca
     Key Container = 52668461-19b4-4fef-80d6-5982ff702c3b
     Unique container name: 0893f8f220ed765fabe249818ff664b9_bba0a089-1c2b-49c8-9f49-e4b211a91a55
     Provider = Microsoft Strong Cryptographic Provider
   Encryption test passed
  • 写回答

1条回答 默认 最新

  • dongzhoulong1797 2016-09-21 06:49
    关注

    You need to use a negative lookahead assertion.

    CN=My_Root_CA(?:(?!={4,})[\s\S])*?Non-root Certificate(?:(?!={4,})[\s\S])*?Key Container\s+=\s+(.*\b)
    

    (?:(?!={4,})[\s\S])*? -> won't go beyond four = signs.

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入