axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/contrib/wss4j/samples/dotNETClient .cvsignore X509CertificateStoreDialog.resx Client.cs JavaProxy.cs X509CertificateStoreDialog.cs build.bat
Date Tue, 14 Oct 2003 12:06:52 GMT
dims        2003/10/14 05:06:52

  Added:       contrib/wss4j/samples/dotNETClient .cvsignore
                        X509CertificateStoreDialog.resx Client.cs
                        JavaProxy.cs X509CertificateStoreDialog.cs
                        build.bat
  Log:
  ******* WORK IN PROGRESS *******
  
  Initial check-in of my sandbox for ws-security related code.
  
  Revision  Changes    Path
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.exe
  
  
  
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/X509CertificateStoreDialog.resx
  
  Index: X509CertificateStoreDialog.resx
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  <root>
    <!-- 
              Microsoft ResX Schema 
          
              Version 1.3
                  
              The primary goals of this format is to allow a simple XML format 
              that is mostly human readable. The generation and parsing of the 
              various data types are done through the TypeConverter classes 
              associated with the data types.
          
              Example:
          
                  ... ado.net/XML headers & schema ...
                  <resheader name="resmimetype">text/microsoft-resx</resheader>
                  <resheader name="version">1.3</resheader>
                  <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms,
...</resheader>
                  <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms,
...</resheader>
                  <data name="Name1">this is my long string</data>
                  <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
                  <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
                      [base64 mime encoded serialized .NET Framework object]
                  </data>
                  <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
                      [base64 mime encoded string representing a byte array form of the .NET
Framework object]
                  </data>
          
              There are any number of "resheader" rows that contain simple 
              name/value pairs.
              
              Each data row contains a name, and value. The row also contains a 
              type or mimetype. Type corresponds to a .NET class that support 
              text/value conversion through the TypeConverter architecture. 
              Classes that don't support this are serialized and stored with the 
              mimetype set.
                       
              The mimetype is used for serialized objects, and tells the 
              ResXResourceReader how to depersist the object. This is currently not 
              extensible. For a given mimetype the value must be set accordingly:
          
              Note - application/x-microsoft.net.object.binary.base64 is the format 
                     that the ResXResourceWriter will generate, however the reader can 
                     read any of the formats listed below.
          
              mimetype: application/x-microsoft.net.object.binary.base64
              value   : The object must be serialized with 
                      : System.Serialization.Formatters.Binary.BinaryFormatter
                      : and then encoded with base64 encoding.
          
              mimetype: application/x-microsoft.net.object.soap.base64
              value   : The object must be serialized with 
                      : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
                      : and then encoded with base64 encoding.
              mimetype: application/x-microsoft.net.object.bytearray.base64
              value   : The object must be serialized into a byte array 
                      : using a System.ComponentModel.TypeConverter
                      : and then encoded with base64 encoding.
          -->
    <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xsd:element name="root" msdata:IsDataSet="true">
        <xsd:complexType>
          <xsd:choice maxOccurs="unbounded">
            <xsd:element name="data">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"
/>
                  <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"
/>
                </xsd:sequence>
                <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
                <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
                <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="resheader">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"
/>
                </xsd:sequence>
                <xsd:attribute name="name" type="xsd:string" use="required" />
              </xsd:complexType>
            </xsd:element>
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    <resheader name="resmimetype">
      <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
      <value>1.3</value>
    </resheader>
    <resheader name="reader">
      <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
      <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <data name="$this.Name">
      <value>SelectCertificateDialog</value>
    </data>
  </root>
  
  
  
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/Client.cs
  
  Index: Client.cs
  ===================================================================
  using System;
  using Microsoft.Web.Services;
  using Microsoft.Web.Services.Security;
  using System.Web.Services.Protocols;
  using Microsoft.Web.Services.Security.X509;
  
  namespace Client
  {
  	class Class1
  	{
          private static void Syntax()
          {
              Console.WriteLine("Usage:  Client /a number /b number [certificate_key_id]");
              Console.WriteLine(" Required arguments:");
              Console.WriteLine("	/a			An integer.  First number to add.");
              Console.WriteLine("	/b			An integer.  Second number to add.");
              Console.WriteLine("\nOne or more of the required arguments are missing or incorrectly
formed.\n");
          }
  
  		static void Main(string[] args)
  		{
              // Check the syntax
              if (args.Length < 4)
              {
                  Syntax();
                  return;
              }
  
              String alias = "";
              if(args.Length == 5) {
                  alias = args[4];
              }
  
              // Set the arguments
              int argA = Int32.Parse(args[1]);
              int argB = Int32.Parse(args[3]);
  
              JavaProxy ip = new JavaProxy();
              
              // Create new contexts from the services
              SoapContext ipReqContext = ip.RequestSoapContext;
  
              // Prompt the user for the required X509 Certificate to use...
              X509SecurityToken token = GetSecurityToken(alias);
              if (token == null)
                  throw new ApplicationException("No key provided for signature.");
  
              // Add the security token to the Java Proxy
              ipReqContext.Security.Tokens.Add(token);
              ipReqContext.Security.Elements.Add(new Signature(token));
              ipReqContext.Path.MustUnderstand = false;
              
              Console.WriteLine("Calling the Java X509 Service...");
              Console.WriteLine(ip.addInt(argA,argB));	
  		}
  
          /// <summary>
          /// Gets the security token for signing messages.
          /// </summary>
          /// <returns>The X509SecurityToken to sign with</returns>
          protected static X509SecurityToken GetSecurityToken(string certKeyID)
          {            
              X509SecurityToken securityToken;  
              //
              // open the current user's certificate store
              //
              X509CertificateStore store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore);
              bool open = store.OpenRead();
  
              try 
              {
                  Microsoft.Web.Services.Security.X509.X509Certificate cert = null;
                  if (certKeyID == null || certKeyID.Length == 0)
                  {
                      //
                      // Open a dialog to allow user to select the certificate to use
                      //
                      StoreDialog dialog = new StoreDialog(store);
                      cert = dialog.SelectCertificate(IntPtr.Zero, "Select Certificate", "Choose
a Certificate below for signing.");                    
                  }
                  else
                  {
                      byte[] keyId = Convert.FromBase64String(certKeyID);
                      X509CertificateCollection matchingCerts = store.FindCertificateByKeyIdentifier(keyId);
                      if (matchingCerts.Count == 0)
                      {
                          throw new ApplicationException("No matching certificates were found
for the key ID provided.");
                      }
                      else
                      {
                          // pick the first one arbitrarily
                          cert = matchingCerts[0];
                      }
                  }
  
                  if (cert == null) 
                  {
                      throw new ApplicationException("You chose not to select an X509 certificate
for signing your messages.");
                  }
                  else if (!cert.SupportsDigitalSignature || cert.Key == null ) 
                  {
                      throw new ApplicationException("The certificate must support digital
signatures and have a private key available.");
                  }
                  else 
                  {
                      byte[] keyId = cert.GetKeyIdentifier();
                      Console.WriteLine("Key Name                       : {0}", cert.GetName());
                      Console.WriteLine("Key ID of Certificate selected : {0}\n", Convert.ToBase64String(keyId));
                      securityToken = new X509SecurityToken(cert);
                  }
              } 
              finally 
              {
                  if (store != null) { store.Close(); }
              }            
              return securityToken;            
          }
  	}
  }
  
  
  
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/JavaProxy.cs
  
  Index: JavaProxy.cs
  ===================================================================
  //------------------------------------------------------------------------------
  // <autogenerated>
  //     This code was generated by a tool.
  //     Runtime Version: 1.0.3705.288
  //
  //     Changes to this file may cause incorrect behavior and will be lost if 
  //     the code is regenerated.
  // </autogenerated>
  //------------------------------------------------------------------------------
  
  // 
  // This source code was auto-generated by wsdl, Version=1.0.3705.288.
  // 
  using System.Diagnostics;
  using System.Xml.Serialization;
  using System;
  using System.Web.Services.Protocols;
  using System.ComponentModel;
  using System.Web.Services;
  
  using Microsoft.Web.Services;
  
  
  /// <remarks/>
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Web.Services.WebServiceBindingAttribute(Name="LogTestServiceSoapBinding", Namespace="http://127.0.0.1:8080/axis/services/http://localhost:8080/LogTestService")]
  public class JavaProxy : WebServicesClientProtocol {
      
      /// <remarks/>
      public JavaProxy() {
          this.Url = "http://localhost:8080/axis/services/http://localhost:8080/LogTestService";
      }
      
      /// <remarks/>
      [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://security",
ResponseNamespace="http://138.42.188.119:8080/axis/services/http://localhost:8080/LogTestService")]
      [return: System.Xml.Serialization.SoapElementAttribute("addIntReturn")]
      public int addInt(int in0, int in1) {
          object[] results = this.Invoke("addInt", new object[] {
                      in0,
                      in1});
          return ((int)(results[0]));
      }
      
      /// <remarks/>
      public System.IAsyncResult BeginaddInt(int in0, int in1, System.AsyncCallback callback,
object asyncState) {
          return this.BeginInvoke("addInt", new object[] {
                      in0,
                      in1}, callback, asyncState);
      }
      
      /// <remarks/>
      public int EndaddInt(System.IAsyncResult asyncResult) {
          object[] results = this.EndInvoke(asyncResult);
          return ((int)(results[0]));
      }
  }
  
  
  
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/X509CertificateStoreDialog.cs
  
  Index: X509CertificateStoreDialog.cs
  ===================================================================
      using System;
      using System.Collections;
      using System.Runtime.InteropServices;
      using System.Windows.Forms;
  
      using Microsoft.Web.Services.Security.X509;
  
      public class StoreDialog
      {
          X509CertificateStore store;
  
          public StoreDialog(X509CertificateStore store)
          {
              this.store = store;
          }
  
          static bool IsWinXP()
          {
              OperatingSystem os = Environment.OSVersion;
              Version v = os.Version;
  
              if ( os.Platform == PlatformID.Win32NT && v.Major >= 5 &&
v.Minor >= 1 )
              {
                  return true;
              }
  
              return false;
          }
  
          /// <summary>
          /// Displays a dialog that can be used to select a certificate from the store.
          /// </summary>
          public X509Certificate SelectCertificate(IntPtr hwnd, string title, string displayString)
          {
              if ( store.Handle == IntPtr.Zero )
                  throw new InvalidOperationException("Store is not open");
  
              if ( IsWinXP() )
              {
                  IntPtr certPtr = CryptUIDlgSelectCertificateFromStore(store.Handle, hwnd,
title, displayString, 0/*dontUseColumn*/, 0 /*flags*/, IntPtr.Zero);
                  if ( certPtr != IntPtr.Zero )
                  {
                      return new X509Certificate(certPtr);
                  }
              }
              else
              {
                  SelectCertificateDialog dlg = new SelectCertificateDialog(store);
                  if ( dlg.ShowDialog() != DialogResult.OK )
                  {
                      return null;
                  }
                  else
                  {
                      return dlg.Certificate;
                  }
              }
  
              return null;
          }
  
          [DllImport("cryptui", CharSet=CharSet.Unicode, SetLastError=true)]
          internal extern static IntPtr CryptUIDlgSelectCertificateFromStore(IntPtr hCertStore,
IntPtr hwnd, string pwszTitle, string pwszDisplayString, uint dwDontUseColumn, uint dwFlags,
IntPtr pvReserved);
      }
  
      /// <summary>
      /// SelectCertificateDialog.
      /// </summary>
      class SelectCertificateDialog : System.Windows.Forms.Form
      {
          /// <summary>
          /// Required designer variable.
          /// </summary>
          private System.Windows.Forms.Button _okBtn;
          private System.Windows.Forms.Button _cancelBtn;
  
          private X509CertificateStore _store;
          private System.Windows.Forms.ListView _certList;
          private System.Windows.Forms.ColumnHeader _certName;
          private X509Certificate _certificate = null;
  
          public SelectCertificateDialog(X509CertificateStore store) : base()
          {
              _store = store;
  
              // Required for Windows Form Designer support
              //
              InitializeComponent();
  
              // Create columns for the items and subitems.
              _certList.Columns.Add("Name", 200, HorizontalAlignment.Left);
              _certList.Columns.Add("Issued By", -2, HorizontalAlignment.Left);
              _certList.Columns.Add("Full Name", -2, HorizontalAlignment.Left);
              _certList.Columns.Add("Certificate Identifier", -2, HorizontalAlignment.Left);
          }
  
          public X509Certificate Certificate
          {
              get
              {
                  return _certificate;
              }
          }
  
          /// <summary>
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// </summary>
          private void InitializeComponent()
          {
              this._okBtn = new System.Windows.Forms.Button();
              this._cancelBtn = new System.Windows.Forms.Button();
              this._certList = new System.Windows.Forms.ListView();
              this._certName = new System.Windows.Forms.ColumnHeader();
              this.SuspendLayout();
              // 
              // _okBtn
              // 
              this._okBtn.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
              this._okBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
              this._okBtn.Location = new System.Drawing.Point(288, 256);
              this._okBtn.Name = "_okBtn";
              this._okBtn.TabIndex = 1;
              this._okBtn.Text = "OK";
              this._okBtn.Click += new System.EventHandler(this.OkBtn_Click);
              // 
              // _cancelBtn
              // 
              this._cancelBtn.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
              this._cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
              this._cancelBtn.Location = new System.Drawing.Point(368, 256);
              this._cancelBtn.Name = "_cancelBtn";
              this._cancelBtn.TabIndex = 2;
              this._cancelBtn.Text = "Cancel";
              this._cancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
              // 
              // _certList
              // 
              this._certList.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

                  | System.Windows.Forms.AnchorStyles.Left) 
                  | System.Windows.Forms.AnchorStyles.Right);
              this._certList.FullRowSelect = true;
              this._certList.MultiSelect = false;
              this._certList.Name = "_certList";
              this._certList.Size = new System.Drawing.Size(456, 248);
              this._certList.TabIndex = 3;
              this._certList.View = System.Windows.Forms.View.Details;
              // 
              // _certName
              // 
              this._certName.Text = "Name";
              this._certName.Width = 92;
              // 
              // SelectCertificateDialog
              // 
              this.AcceptButton = this._okBtn;
              this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
              this.CancelButton = this._cancelBtn;
              this.ClientSize = new System.Drawing.Size(456, 286);
              this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                            this._certList,
                                                                            this._cancelBtn,
                                                                            this._okBtn});
              this.Name = "SelectCertificateDialog";
              this.Text = "SelectCertificateDialog";
              this.ResumeLayout(false);
  
          }
  
          protected override void OnLoad(EventArgs e)
          {
              base.OnLoad(e);
  
              if ( _store == null )
              {
                  throw new Exception("No store to open");
              }
  
              if ( _store.Handle == IntPtr.Zero )
              {
                  throw new Exception("Store not open for reading");
              }
  
              X509CertificateCollection coll = _store.Certificates;
  
              foreach(X509Certificate cert in coll)
              {
                  ListViewItem item = new CertificateListViewItem(cert);
                  _certList.Items.Add(item);
              }
          }
  
          private void OkBtn_Click(object sender, System.EventArgs e)
          {
              _certificate = null;
  
              if ( _certList.SelectedItems != null && _certList.SelectedItems.Count
== 1 )
              {                
                  _certificate = ((CertificateListViewItem)_certList.SelectedItems[0]).Certificate;
              }
  
              this.Close();
              this.DialogResult = DialogResult.OK;
          }
  
          private void CancelBtn_Click(object sender, System.EventArgs e)
          {
              _certificate = null;
              this.DialogResult = DialogResult.Cancel;
          }
  
          class CertificateListViewItem : ListViewItem
          {
              X509Certificate cert;
  
              public CertificateListViewItem(X509Certificate certificate) : base(GetSubItems(certificate))
              {
                  cert = certificate;
              }
  
              static string GetCommonName(string name)
              {
                  if (name == null || name.Length == 0)
                  {
                      return string.Empty;
                  }
  
                  string [] fields = name.Split(',');
                  for (int i = 0; i < fields.Length; i++)
                  {
                      string field = fields[i];
                      if (field == null)
                          break;
                      
                      field = field.Trim();
                      if (field.StartsWith("CN="))
                      {
                          return field.Substring(3);
                      }
                  }
                  return "<Common Name not found>";
              }
  
              static string[] GetSubItems(X509Certificate certificate)
              {
                  string issuedTo = certificate.GetName();
                  string issuedBy = GetCommonName(certificate.GetIssuerName());
                  string certKeyId = Convert.ToBase64String(certificate.GetKeyIdentifier());
  
                  string simpleName = GetCommonName(issuedTo);                
  
                  return new string [] { simpleName, issuedBy, issuedTo, certKeyId };
              }
  
              public X509Certificate Certificate
              {
                  get
                  {
                      return cert;
                  }
              }
          }
      }
  
  
  
  
  1.1                  ws-axis/contrib/wss4j/samples/dotNETClient/build.bat
  
  Index: build.bat
  ===================================================================
  csc *.cs /r:"C:\Program Files\Microsoft WSE\v1.0.2312\Microsoft.Web.Services.dll" 
  
  
  

Mime
View raw message