Need some help if someone has some time. I am in the process of writing a script in Python that will find a private key and a certificate and just replace them with some junk.
Based on the below text, I was able to somehow come up with a regex to locate the text in the document, but I can't get the python section to work in Notepad++. Can someone help me on where I messed up on the syntax of my python script? I am currently using Notepad++ 6.3
Regex is: ^DEK-Info: .[\t\r\n\v\f]-----END CERTIFICATE-----.$
Python Line is: editor.pymlreplace(r"^DEK-Info: .[\t\r\n\v\f]-----END CERTIFICATE-----.$", "TOP SECRET INFORMATION")
Source Text:
config vpn certificate local
edit "FF-0123"
set password ENC XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
set private-key "-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,A0C806460D1CB123
You're being bitten by a couple of things here. The easy one is you need the dot (.) character to match newlines, which you can do by adding re.DOTALL to the flags, which is the fourth parameter to pymlreplace(). However, adding that flag doesn't fix it.
The second thing is uglier, and I'm hoping will be solved in the new version (but I've not tested it yet, so no promises!). $ is a non-capturing match that only matches \n. Assuming your document is \r\n, you need a \r before the $ to match the \r at the end of the line. This is buried in the docs somewhere.
Hello,
Need some help if someone has some time. I am in the process of writing a script in Python that will find a private key and a certificate and just replace them with some junk.
Based on the below text, I was able to somehow come up with a regex to locate the text in the document, but I can't get the python section to work in Notepad++. Can someone help me on where I messed up on the syntax of my python script? I am currently using Notepad++ 6.3
Regex is: ^DEK-Info: .[\t\r\n\v\f]-----END CERTIFICATE-----.$
Python Line is: editor.pymlreplace(r"^DEK-Info: .[\t\r\n\v\f]-----END CERTIFICATE-----.$", "TOP SECRET INFORMATION")
Source Text:
config vpn certificate local
edit "FF-0123"
set password ENC XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
set private-key "-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,A0C806460D1CB123
1sE6QWq7DHWQPV6cY6C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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OXkeDg9h4O4DisIx9Jg6ZEpIzGz1f0W6OYdzuHCnGnPCNGdqTT+nr4kQlx48Vmb4
keqo17Sh2PawO+o7ZUHXesp7Pvam1KyTPiegbI83XEB25Q==
-----END CERTIFICATE-----"
set scep-url "http://X.X.X.X/cgi-bin/pkiclient.exe"
set source-ip X.X.X.X
set auto-regenerate-days 30
set auto-regenerate-days-warning 15
You're being bitten by a couple of things here. The easy one is you need the dot (.) character to match newlines, which you can do by adding re.DOTALL to the flags, which is the fourth parameter to pymlreplace(). However, adding that flag doesn't fix it.
The second thing is uglier, and I'm hoping will be solved in the new version (but I've not tested it yet, so no promises!). $ is a non-capturing match that only matches \n. Assuming your document is \r\n, you need a \r before the $ to match the \r at the end of the line. This is buried in the docs somewhere.
So the line that works is:
Last edit: Dave Brotherstone 2014-02-12