signer icon indicating copy to clipboard operation
signer copied to clipboard

Removing namespaces and elements

Open taq opened this issue 5 years ago • 0 comments

Hi!

Thanks for this gem. I'm using it to sign some XML files here, but our local government has some custom and strict rules for the documents. I'm using this code:

signer  = Signer.new(data)
signer.cert = OpenSSL::X509::Certificate.new(File.read(files[:cert]))
signer.private_key  = OpenSSL::PKey::RSA.new(File.read(files[:key]), File.read(files[:pwd]).chomp)
signer.security_node  = signer.document.root
signer.security_token_id = ""
signer.digest!(signer.document.root, :id => "id", :enveloped => true)
signer.sign!(:issuer_serial => true)
signer.to_xml

And I'd like to check if is possible to:

  1. Remove namespaces. I need xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id" be removed from the main element. They just want their custom namespace.

  2. Remove some elements. To conform to their XSD, I need to remove the elements <X509SubjectName>, <X509IssuerSerial>, <KeyValue>, <RSAKeyValue>, <Modulus> and <Exponent>.

  3. Change reference URI. To conform to their XSD, I need to replace the "#id" on Reference URI="#id" to a custom one.

  4. Insert new elements. I need to insert <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> before `</Transforms>' ends.

  5. Remove new lines. They won't allow a new line after <?xml version="1.0"?>, I need the signed result to don't use newline character. I could remove on the result, but seems the sign would be invalid if it was there when signing.

Thanks!

taq avatar Nov 26 '18 14:11 taq