發表文章

目前顯示的是 2月, 2018的文章

Azure Web Apps 讀取憑證

一般當我們在本機能正常運作的東西 常常放到雲端就不Work了 很多問題其實就在於雲端環境的差異與限制 例如這次研究的問題->讀取憑證資訊 以下就介紹Azure Web Apps環境下 憑證如何放置與讀取的差異 一般我們系統要讀取的憑證會放在 StoreLocation.LocalMachine Azure Web Apps上傳後的憑證是放在 StoreLocation.CurrentUser 要讓程式能讀取到要讀取的憑證還要設定憑證的設定檔 否則就算你上傳憑證之後還是找不到 APP Setting中新增憑證讀取參數 WEBSITE_LOAD_CERTIFICATES 和憑證指紋(thumbprint) 或者也可以設定"*"(不需要引號)就會讀取全部憑證 這樣就能順利讀取 以下是憑證讀取範例 using System; using System.Security.Cryptography.X509Certificates;namespace UseCertificateInAzureWebsiteApp { class Program { static void Main(string[] args) { X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find( X509FindType.FindByThumbprint, // 憑證指紋 “E661583E8FABEF4C0BEF694CBC41C28FB81CD870”, false);

解決WCF(REST)在https出現檔案找不到錯誤

最近發生的問題 在網站掛上https之後 一些WCF(REST)服務出現在https出現檔案找不到錯誤 但http狀態下卻是正常的 發現原來是要對設定黨做一些調整 以下是調整後的範例 <system.serviceModel> <bindings> <webHttpBinding> <binding name="Binding" crossDomainScriptAccessEnabled="true"> <security mode="Transport"> <transport clientCredentialType="None" /> </security> </binding> <binding name="httpbind" crossDomainScriptAccessEnabled="true"> </binding> </webHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="returnFaults"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointB

解除安裝Visual Studio

隨著Visual Studio的改版,大約一兩年就改版一次 所以常常會發先電腦同時安裝有多個 Visual Studio版本 不過通常舊版本的功能在新版本都能通用 所以找一下如何解除安裝的方法,空出硬碟空間,多下載幾部謎面(疑?) 發現其實很簡單,在安裝光碟下的執行檔(vs_開頭的執行檔,不同版本檔案名稱不同)加上 /unistall /force 即可解除安裝 此命令是解除安裝 Visual Studio 以及與其他產品共用的所有功能 D:\vs_ultimate.exe /uninstall /force 其他命令列參數(不區分大小寫)可以使用/?叫出說明畫面 參考 安裝 Visual Studio

Windows 10 修復

前陣子因不當關機導致系統啟動發生一些問題 看事件檢視器看到一堆錯誤訊息 因為不想重灌,所以看看有什麼正規的解法 順便將寫流程紀錄一下,讓有同樣問題的可以參考看看 一開始用系統管理員在[命令提示字元]先下 SFC /SCANNOW 一般這個指令可以即可以修復系統的錯誤 不過我執行完後仍有修正一些,因為一些檔案無法毀損無法修復 所以接著嘗試利用 dism /online /cleanup-image /restorehealth 如果不行最後這步驟需要放入Win 10光碟 利用光碟裡面的檔案做回復修正 DISM /Online /Cleanup-Image /RestoreHealth /source:WIM:X:\Sources\Install.wim:1 /LimitAccess 光碟版本要和安裝版本一致 否則可能出現以下錯誤 Error: 0x800f081f The source file could not be found. 修正完之後可以再執行一次 SFC /SCANNOW 參考 System File Checker DISM 映像管理命令列選項

Visual Studio開發Python超簡單

圖片
最近因為需求需要使用Python開發一些程式 很久前就知道Visual Studio有支援Python開發 不過那時候似乎還不太方便,支援度也比較差? 最近又試一下 發現真不虧是地表最強IDE,想要的一些功能基本上都有了 新增Python專案 可以選擇現有Python,新建Python或IronPython 下載安裝Python,支援2.7.x或3.x版 可以切換interpreter版本 最後感到最驚奇的應該是支援debug,區域變數查看 參考 Python 適用於 Visual Studio 的 Python 工具

IIS 啟用HTTP Strict Transport Security (HSTS)

1.設定header加上Strict-Transport-Security和持續時間 <system.webServer> <httpProtocol> <customHeaders> <add name="Strict-Transport-Security" value="max-age=31536000"/> </customHeaders> </httpProtocol> </system.webServer> 不過這邊要特別注意的是要在HTTPS下送出這個Header,而不要在HTTP狀態下送出這個Header 因為根據 HSTS (RFC6797) spec 有提到 An HTTP host declares itself an HSTS Host by issuing to UAs (User Agents) an HSTS Policy, which is represented by and conveyed via the Strict-Transport-Security HTTP response header field over secure transport (e.g., TLS). 2.利用Rewrite模組強制使HTTP連線導致HTTPS <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="o

快速的雜湊演算法破壞了加密的安全性

像MD5、SHA和SHA1之類的快速雜湊演算法的用意並不在安全性——保護重要的信息,特別是密碼,雜湊演算法必須有意地減慢反向暴力破解速度。 Troy Hunt 是一位微軟的MVP,它展示了 SqlMembershipProvider 所提供的密碼雜湊值如何易於被暴力破解。 SqlMembershipProvider是VS 2010中ASP.NET web應用程序模板中的預設成員(membership)提供程序。Troy在他的文章 《我們的密碼雜湊值沒有遮蔽(Our password hashing has no clothes)》 中展示了經過SqlMembershipProvider中SHA1雜湊演算法處理的密碼安全性是如何被破解的,其中使用的是GPU、名為 hashkiller 的字典以及暴力破解演算法。在規模為40000條的真實密碼樣本中(來自於之前的一次攻擊),演算法在45分鐘內破解了24710個,佔總體樣本的67%。 其中包括被認為是很強壯的密碼: 像「volleyball6」,有11個字元,兩種字元類型。甚至還有「 zaq1@WSX 」——由八個字元組成,其中有大寫、小寫、數字和符號,肯定足以通過大多數安全策略,但是即便被存儲為「安全的」雜湊值,也完全沒用。 問題在於你擁有了可能的密碼字典之後可以快速創建新的雜湊值,並且硬件變得越來越快。 那麼如何來解決這個問題呢? 密鑰延伸(Key stretching) ,通過多次迭代雜湊演算法,能夠提供一種方式來讓雜湊演算法變得足夠慢,使得暴力破解更加困難。 Bcrypt 和 PBKDF2 都是這樣的算法——它們叫做適應性算法,因為通過增加迭代的次數,會隨著時間推移而變得更慢(因為硬件變得更快)。 Bcrypt.NET 實現了前者,而DefaultMembershipProvider實現了後者。 DefaultMembershipProvider對SHA1使用了1000次迭代,它是VS2012的ASP.NET MVC 4模板政所提供的預設選項。Troy的文章 《.NET中更強的密碼雜湊演算法(Stronger password hashing in .NET)》 說明了如何使用這些方法,以及如何把應用程序遷移到使用更強壯的雜湊演算法,而不會破壞你的身份驗證過程。

Asirra

Asirra is a human interactive proof that asks users to identify photos of cats and dogs. It's powered by over three million photos from our unique partnership with Petfinder.com . Protect your web site with Asirra — free! Overview Web services are often protected with a challenge that's supposed to be easy for people to solve, but difficult for computers. Such a challenge is often called a CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) or HIP (Human Interactive Proof). HIPs are used for many purposes, such as to reduce email and blog spam and prevent brute-force attacks on web site passwords. Today, the most common HIPs ask users to identify text that has been distorted or obscured, like the example seen to the right. Unfortunately, such challenges can be difficult and frustrating for people, yet are often easily solved by computers. Asirra (Animal Species Image Recognition for Restricting Access) is a HIP that works by asking users