Chrome Trendnet cloud plugin problem

I have a Trendnet cloud IP cam at home.  Ususally I can browse to it through the trendnet proxy.  But today it wouldn't work in Chrome.  Kept prompting me to install the plugin.  I knew Chrome was in the process of not supporting plugins so I figured this was the reason.  So how to enable it?

google "npapi chrome enable"

chrome://flags/#enable-npapi , set to enable

System.Diagnostics.TextWriterTraceListener with ASP.Net 4

I spent hours trying to figure out why my web app wasn't writing to a debug file.

I had this in my web.config

  <trace autoflush="true">
      <add name="textLogListener" type="System.Diagnostics.TextWriterTraceListener"
           initializeData="myapp.log"  />
      <remove name="Default" />

And in my .cs code added
System.Diagnostics.Trace.WriteLine("Hello World");

Worked great in VS2012 but when I published it to a server, no file was created.   

I'm guessing that the ASP.Net compiler wasn't using the trace and debug flags.  The simple fix was adding 

#define TRACE

to the top of the .cs file I was working with.

Simple but not obvious

Get SSH public key fingerprint with powershell

I was working on a project with SSH keys.  I needed to get the key fingerprint but don't have access to ssh-keygen.  So with some poking around I was able to get the MD5 hash of the base64 keyfile.

Here's the code:

$keyFilePath = ""
#Get the key
$rawText = [System.IO.File]::ReadAllText($keyFilePath)
$rawText = $rawText.Replace("`r","")
$rawText = $rawText.Replace("`n","")
$rawText -match "AA.+?=="
$keyText = $Matches[0]

#Compute the hash
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$bd= [System.Convert]::FromBase64String($keyText);
$hash = [System.BitConverter]::ToString($md5.ComputeHash($bd))

Summer Calendar

Here is our summer schedule

Powershell MSMQ

I had to write a function to send MSMQ messages using powershell.  Here is the code that builds on an earlier post sending Unicode text messages with MSMQ

function SendMSMQ

$messageBody = $messageBody.replace("\<\?.+\>\r\n", "").Trim()

if($messageBody.length -gt 0)
 $queue = new-object System.Messaging.MessageQueue($queueName)
 $msg = new-object System.Messaging.Message
 $msg.Label = $messageLabel
 $enc = new-object System.Text.UnicodeEncoding($false, $false)
 $writer = new-object System.IO.StreamWriter($msg.BodyStream, $enc)
 $msg.BodyType = 8
 $queue.Send($msg, [System.Messaging.MessageQueueTransactionType]::Single)
 write-host $messageBody


Win2003 Certs

I was working on installing a ServiceBus 1.1 client app on a Windows 2003 server.  I installed the server certs and crl on the client machine.  However I was still receiving the message:

System.UnauthorizedAccessException: The token provider was unable to provide a security token while accessing 
'https://myserver:9355/ServiceBusDefaultNamespace/$STS/Windows/'. Token provider returned message: 
'The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.'.
 ---> System.IdentityModel.Tokens.SecurityTokenException: The token provider was unable to provide a security 
 token while accessing 'https://myserver:9355/ServiceBusDefaultNamespace/$STS/Windows/'. 
 Token provider returned message: 'The underlying connection was closed: Could not establish trust relationship
 for the SSL/TLS secure channel.'. ---> System.Net.WebException: The underlying connection was closed: Could not
  establish trust relationship for the SSL/TLS secure channel. ---> 
  System.Security.Authentication.AuthenticationException: The remote certificate is
   invalid according to the validation procedure.

When I viewed https://myserver:9355/ServiceBusDefaultNamespace in the browser the cert had an exception of "This certificate has an nonvalid digital signature."
I looked at the cert in certmanager and noticed the signing algorithm was 1.2.840.113549.1.1.11  Apparently the SHA256 algorithm was not installed on the server.  I had to apply a hotfix from

Powershell COM objects

I was trying to create a COM object in powershell like this

$obj= New-Object -ComObject MyProject.MyClass

When I ran it I received this error:
New-Object : Retrieving the COM class factory for component with CLSID {E51BB9FD-F8EF-4636-8DE3-1ADE61B670AD} failed due to the following error: 80040154 Class not registered (Exception 

I just used regsvr32 on the dll so I knew it was registered and I verified it with regedit

Figured out I was running the 64bit version of powershell.  It worked using the 32bit version.

I also noticed that if the COM object is not registered the error is 
New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception 
from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

LocalSTS Web.config

I've been working on some Windows Identity Framework project and have been using the cool localSTS tool for claims authentication.  The one thing I did notice is that the web.config for the project is overridden when the localSTS is configured.  After my project was running correctly, I went in and added some claims to the existing configuration. When I started the project again the Windows Cardspace app popped up and there was a message

"Incoming policy failed validation."

Took me forever to figure out that the localSTS config replaced the existing issuermetadata element with

              <issuerMetadata address="https://localhost/adfs/services/trust/mex" />

The address should be something like https://localsts:port/wsTrustSTS/mex

How to get Service Bus for Windows client config

I installed the Service Bus for Windows Server application but did not save the client connection string.  I found out later how to do it so here it is.

1.  Open the Service Bus Powershell link under the Service Bus group (or add the ServiceBus PowerShell ps1 file)
2.  Execute the Get-SBClientConfiguration command.  

SAML2 FederationMetadata validation

I was working on a project using a SAML2 FederationMetadata document.  The Xml signature of the document had to be verified.  I had some issues out of the box so I thought I'd document them

"SignatureDescription could not be created for the signature algorithm supplied."

First issue was with the signature using the "" encryption.  For some reason it's not included in System.Security.Cryptography.Xml.SignedXml so the following class has to be added

    public class RSAPKCS1SHA256SignatureDescription : SignatureDescription
        public RSAPKCS1SHA256SignatureDescription()
            base.KeyAlgorithm = "System.Security.Cryptography.RSACryptoServiceProvider";
            base.DigestAlgorithm = "System.Security.Cryptography.SHA256Managed";
            base.FormatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureFormatter";
            base.DeformatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter";

        public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
            AsymmetricSignatureDeformatter asymmetricSignatureDeformatter = (AsymmetricSignatureDeformatter)
            return asymmetricSignatureDeformatter;

Before you create the SignedXml object the Encrytion algorithm has to added to the config
            CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "");

            SignedXml signedXml = new SignedXml(metadataXmlDocument);

Net issue I had was the signedXml.CheckSignature(certificate, false) returning false for valid signed files.  The issue was that the certificate was not in the trusted root certificate store.  Why that matters I'm not sure but the issue went away after I added it.