• Visual studio project configuration file settings priority

    csproj in explorerTHE PROBLEM
    For multiple versions (Dev, Test, Prod) of a single ClickOnce application one has to name assemblies differently. In this way you can have all three versions on the same computer. This can be easily achieved by using configuration in Visual Studio. The problem I had was that no matter what the assembly name I specified in the configuration, it would not use it during build.

    SOLUTION
    The problem was hidden on the bottom of the “application.csproj” file. All the properties of each configuration were placed on top of the csproj file and the bottom parameter was always setting like a default value.

     
    .
    .
    .
    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
       <OutputPath>bin\Release\</OutputPath>
       <DefineConstants>TRACE</DefineConstants>
       <Optimize>true</Optimize>
       <DebugType>pdbonly</DebugType>
       <PlatformTarget>AnyCPU</PlatformTarget>
       <ErrorReport>prompt</ErrorReport>
       <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
       <AssemblyName>Application Test</AssemblyName>
       <ProductName>Application Test</ProductName>
       <InstallUrl>https://localhost/install/</InstallUrl>
       <PublishUrl>C:\Deploy\</PublishUrl>
       <UseVSHostingProcess>false</UseVSHostingProcess>
    </PropertyGroup>
    .
    .
    .
    <PropertyGroup>
       <AssemblyName>Application</AssemblyName>
    </PropertyGroup>
    .
    .
    .
    

    Just remove the bottom PropertyGroup and your configuration setting will be applied at build time. Don’t forget to always reload the project when you change the configuration file, as visual studio always reads it only at project load.

    PS: To edit the csproj you must first unload the project. Then you can right click on it and choose edit. (or use a text editor in explorer)

  • Check your e-mail and username

    By: DonkeyHotey
    By: DonkeyHotey

    There is a site where you can check if your email or username or domain had been compromised in any of the security breaches or “pastes” in the past (public display of personal data).

    The site is reachable on this address:

    https://haveibeenpwned.com/

  • Sitecom WLR-5100 firmware v3.0

    390x295For all of those that cannot access the new firmware (v3.0) for WLR-5100 (X5 N600) I give you the link that I received from official support.

    WLR-5100 V1 001: www.service-downloads.com/data/files/Sitecom/WLR-5100v1-001-FW3.0.zip
    WLR-5100 V1 002: www.service-downloads.com/data/files/Sitecom/WLR-5100v1002-V1.2.zip

    This download will be available on their website when they update it. If the links don’t work you can always contact Sitecom’s support.

    I’ve been using the router for about a week now and I am satisfied with the functionality it provides.
    + 2,4 GHz and 5GHz wireless
    + Gigabit LAN (100+ MB/s tested)
    + IPv6 out of the box support
    + Wireless guest network on both frequencies

    – Could not find DLNA integrated server that was mentioned in description
    – no WDS
    – rare information about the inside of the router

    Have a nice day.

  • Fastest way to create a file list

    Dir helpThe fastest way on Windows to create a file with a list of all files in a directory and its subdirectories  is pretty simple. This should work on most windows desktops. Open the Command Prompt ( Start button -> cmd ) and run the following command.
    The /S switch searches all subdirectories.
    The /B switch ommits all header and other stuff.
    The > forwards all output to the specified filelist.txt file.

     

    dir /B /S > filelist.txt
    

    * For other switches check the output of

    dir /?

    Tested on a structure composed of 1,5M files. Works flawlessly.

  • Avast residues

    Avast is a really nice antivirus program with friendly user interface and easy setup.

    While it works efficiently, it amazed me that it has a really harsh internet firewall that you don’t even know it works. It occurred to me many times that it had something to do with playing lan games using old Hamachi. We could see the server hosted on the pc behind avast, but we could not connect to it. It would just start connecting forever and never coming to a point. Uninstallation of Avast resolved the problem immediately so we knew something was up wit hit. Later it showed up that even disabling only the firewall part worked well.

    The new story that amazed me was also related to avast. The program itself was uninstalled, but a service remained running in the background. Even after many computer restarts. The user could connect everywhere outside but nobody could connect to him. We tried with TeamViewer – no go (
    Error Code: WaitForConnectFailed ), Remote deskotp – didnt work (stalled at initializing … ), RealVNC didn’t work. Any connection to the user pc was failing. We noticed the problem because the user could not connect to an OpenVPN server, probably because the server wasn’t able to make a connection to the user. Firewall were disabled at all.

    Then I notice an avast service running in task manager and it came to my mind that it shouldn’t be there as Avast was previously uninstalled. The avast process could not be killed as the administrator didn’t have enough rights (right! clear as the sky on a rainy day). Fortunately Avast provides the right tool with clear instructions on how to remove it. The process is described at http://www.avast.com/uninstall-utility and easy to follow if you know what safe mode is.

    After removal everything started working normally again.

  • Use iText 4.1.6 to signing a PDF file with C#

    Here is an C# example of signing a PDF file with certificate in file using the latest free MPL & GPL version of iText. It can be downloaded from here (source) or here(DLL) or via NuGet package manager in Visual Studio.

    After importing iText in the project you have access to the following functions.

    The code for PDF processing goes like this:

     var _certificate = new X509Certificate2(@"C:\cert.pfx", "iLikeMyCertPass" , X509KeyStorageFlags.Exportable);
    
    var certParser = new Org.BouncyCastle.X509.X509CertificateParser();
    var chain = new Org.BouncyCastle.X509.X509Certificate[]
        {
          certParser.ReadCertificate(_certificate.RawData)
        };
    AsymmetricKeyParameter bouncyCastlePrivateKey = DotNetUtilities.GetKeyPair(_certificate.PrivateKey).Private;
    
    
    var reader = new PdfReader(@"C:\test.pdf");
    var writer = new FileStream(@"C:\test-signed.pdf"), FileMode.Create, FileAccess.Write);
    
    PdfStamper st = PdfStamper.CreateSignature(reader, writer, '\0');
    
    PdfSignatureAppearance sap = st.SignatureAppearance;
    
    sap.Layer2Font = new Font(Font.UNDEFINED, 4);
    sap.Reason = "I can sign it!";
    sap.Location = "At home";
    
    sap.SetVisibleSignature(new Rectangle(0, 0, 120, 35), reader.NumberOfPages, "Signature");
    sap.Render = PdfSignatureAppearance.SignatureRender.Description;
    sap.SetCrypto(bouncyCastlePrivateKey, chain, null, PdfName.ADOBE_PPKLITE);
    sap.Acro6Layers = true;
    //if I uncomment the following line the status of file is UNKNOWN in Acrobat reader
    //sap.CertificationLevel = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED;
    
    reader.Appendable = true;
    
    var dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED);
    dic.Reason = sap.Reason;
    dic.Contact = sap.Contact;
    dic.Location = sap.Location;
    dic.Date = new PdfDate(sap.SignDate);
    sap.CryptoDictionary = dic;
    
    int contentEstimated = 15000; //you can modify this you have loads of contents in signature
    
    var exc = new Hashtable();
    exc[PdfName.CONTENTS] = contentEstimated*2 + 2;
    sap.PreClose(exc);
    
    PdfPKCS7 sgn = new PdfPKCS7(bouncyCastlePrivateKey, chain, null, "SHA-1", false);
    IDigest messageDigest = DigestUtilities.GetDigest("SHA-1");
    Stream data = sap.RangeStream;
    byte[] buf = new byte[contentEstimated];
    int n;
    while ((n = data.Read(buf, 0, buf.Length)) > 0)
    {
        messageDigest.BlockUpdate(buf, 0, n);
    }
    byte[] hash = new byte[messageDigest.GetDigestSize()];
    messageDigest.DoFinal(hash, 0);
    DateTime cal = DateTime.Now;
    
    byte[] sh = sgn.GetAuthenticatedAttributeBytes(hash, cal, null);
    sgn.Update(sh, 0, sh.Length);
    
    byte[] encodedSig = sgn.GetEncodedPKCS7(hash, cal, null, null);
    if (contentEstimated + 2 < encodedSig.Length)
        throw new Exception("Not enough space");
    
    var paddedSig = new byte[contentEstimated];
    Array.Copy(encodedSig, 0, paddedSig, 0, encodedSig.Length);
    
    var dic2 = new PdfDictionary();
    dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
    sap.Close(dic2);
    

    Leave any feedback if it doesn’t work.

  • Xades standards testing portal

    I just found out a great portal about xml digital signature xades standard testing tool, with detailed information on what is wrong. You just need to send a free email to get the login credentials and you are good to go. They replied to me the next day.

    The link is located at ETSI site: http://xades-portal.etsi.org/pub/index.shtml

    There is a link (lower left part) to the Xades baseline checker online tool which is the final target:http://212.234.160.9/pub/index.shtml. I hope the ip doesn’t change.

    Have fun!

  • Use iText 5.4.x to signing a PDF file

    Here is a sample code to sign a PDF using iTextSharp library and it is using a certificate file (with private key).

    X509Certificate2 cert = new X509Certificate2("C:\\mycert.p12");
    
    Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
    Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] {
    cp.ReadCertificate(cert.RawData)};
    
    IExternalSignature externalSignature = new X509Certificate2Signature(cert, "SHA-1");
    
    PdfReader pdfReader = new PdfReader("C:\\multi-page-test.pdf");
    
    var signedPdf = new FileStream("C:\\multi-page-test-signed.pdf", FileMode.Create);
    
    var pdfStamper = PdfStamper.CreateSignature(pdfReader, signedPdf, '\0');
    PdfSignatureAppearance signatureAppearance = pdfStamper.SignatureAppearance;
    
    signatureAppearance.SignatureGraphic = Image.GetInstance("C:\\logo.png");
    signatureAppearance.Reason = "Because i can";
    signatureAppearance.Location = "Tu podpišem";
    signatureAppearance.SetVisibleSignature(new Rectangle(100, 100, 250, 150), pdfReader.NumberOfPages, "Signature");
    signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;
    
    MakeSignature.SignDetached(signatureAppearance, externalSignature, chain, null, null, null, 0, CryptoStandard.CMS);
    
  • Extract integer serial from x509SerialNumber hex in certificate

    The important thing here is to trim leading zeros that serve just for filling data into byte octets.

    04CF = 4CF
    4CF(hex) = 1231 (int)

    Accessing the certificate serial number can be done in many ways. This is just an example.

    //Load certificate
    X509Certificate2 _certificate = new X509Certificate2("C:\mycert.p12");
    
    //Extract serial number and trim leading zeros
    String serialHex = _certificate.SerialNumber.TrimStart('0');
    
    //Convert from hex to integer (im converting it also to string)
    String serialInteger = int.Parse(serialHex, NumberStyles.HexNumber).ToString();
    
  • Must have WP plugins

    W3 Total Cache
    Plugin designed to cache and speed up your wordpress blog. With loads of setting you can minify css, cache pages, object, database, … You can even use Cloudflare for CDN.

    Smush.it
    A plugin for smashing (compressing) you pictures to the minimum size, but witouth loose of quality.

    WP Socializer
    Social networking integrated on every page and article of your blog. Lots of sites included.

    GTmetrix
    Speed analyzer of your blog with great suggestion on how to improve it.

    Lazy load
    Beautifully loading pictures when they are displayed in a visitors browser. Saves bandwith.
    Loads of other plugins are available at wordpress and this is just a bit I use. Highly recommended.