Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samlsign / samlsign.cpp
index ffb545d..2e67ddf 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
@@ -35,6 +39,7 @@
 #include <saml/saml2/metadata/Metadata.h>
 #include <saml/saml2/metadata/MetadataProvider.h>
 #include <saml/saml2/metadata/MetadataCredentialCriteria.h>
+#include <saml/signature/ContentReference.h>
 #include <saml/signature/SignatureProfileValidator.h>
 #include <saml/util/SAMLConstants.h>
 #include <xmltooling/logging.h>
@@ -120,13 +125,15 @@ int main(int argc,char* argv[])
     char* cr_param=nullptr;
     char* t_param=nullptr;
     char* id_param=nullptr;
+    char* alg_param=nullptr;
+    char* dig_param=nullptr;
 
     // metadata lookup options
     char* m_param=nullptr;
     char* issuer=nullptr;
     char* prot = nullptr;
     const XMLCh* protocol = nullptr;
-    char* rname = nullptr;
+    const char* rname = nullptr;
     char* rns = nullptr;
 
     for (int i=1; i<argc; i++) {
@@ -156,6 +163,10 @@ int main(int argc,char* argv[])
             rname=argv[++i];
         else if (!strcmp(argv[i],"-ns") && i+1<argc)
             rns=argv[++i];
+        else if (!strcmp(argv[i],"-alg") && i+1<argc)
+            alg_param=argv[++i];
+        else if (!strcmp(argv[i],"-dig") && i+1<argc)
+            dig_param=argv[++i];
         else if (!strcmp(argv[i],"-saml10"))
             protocol=samlconstants::SAML10_PROTOCOL_ENUM;
         else if (!strcmp(argv[i],"-saml11"))
@@ -339,6 +350,14 @@ int main(int argc,char* argv[])
 
             // Attach new signature.
             Signature* sig = SignatureBuilder::buildSignature();
+            if (alg_param) {
+                auto_ptr_XMLCh alg(alg_param);
+                sig->setSignatureAlgorithm(alg.get());
+            }
+            if (dig_param) {
+               auto_ptr_XMLCh dig(dig_param);
+               dynamic_cast<opensaml::ContentReference*>(sig->getContentReference())->setDigestAlgorithm(dig.get());
+            }
             signable->setSignature(sig);
 
             // Sign response while re-marshalling.