Jenkins專有使用者資料庫密碼編譯演算法簡析

來源:互聯網
上載者:User

Jenkins專有使用者資料庫密碼編譯演算法簡析

Jenkins存取控制分為:安全域即認證)與授權策略。

其中,安全域可以採用三種形式,分別為:Jenkins專有使用者資料庫、LDAP、Servlet容器代理。

Jenkins專有使用者的資料資訊存放位置: <JENKINS_HOME> /users/

每個使用者的相關資訊存放在config.xml檔案中: <JENKINS_HOME>/users/ <user>/config.xml

在config.xml檔案中 passwordHash節點可以看到使用者名稱加密後的密文雜湊值

那麼,它是用何種加密方式加密的呢?可否解密密文得到明文呢?

在 github上查看其源碼,通過關鍵字 #jbcrypt搜尋定位到 HudsonPrivateSecurityRealm.java這個檔案

HudsonPrivateSecurityRealm.java詳細路徑是:jenkins/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java

通過分析該源碼得知:

1、密文的格式為:salt: encPass,其中以#jbcrypt表示salt作為資料頭

2、明文通過jbcrypt演算法得到密文 encPass

關於jbcrypt:

jbcrypt是bcrypt加密工具的java實現。

它的API非常簡單,DEMO如下,在HudsonPrivateSecurityRealm.java中可以看到加密和校正時使用了如下API:

 
  1. // Hash a password for the first time   
  2. String hashed = BCrypt.hashpw(password, BCrypt.gensalt());   
  3.  
  4. // gensalt's log_rounds parameter determines the complexity the work factor is 2**log_rounds, and the default is 10   
  5. String hashed = BCrypt.hashpw(password, BCrypt.gensalt(12));   
  6.  
  7. // Check that an unencrypted password matches one that has previously been hashed   
  8. if (BCrypt.checkpw(candidate, hashed))   
  9. System.out.println("It matches");   
  10. else   
  11. System.out.println("It does not match");   

經驗證,用jbcrypt對同一個明文加密後因為salt一般不同,加密後的密文一般不同

關於bcrypt:

1、bcrypt是無法復原的密碼編譯演算法,無法通過解密密文得到明文。

2、bcrypt和其他對稱或非對稱式加密方式不同的是,不是直接解密得到明文,也不是二次加密比較密文,而是把明文和儲存的密文一塊運算得到另一個密文,如果這兩個密文相同則驗證成功。

綜上,Jenkins專有使用者資料庫使用了jbcrypt加密,jbcrypt加密是無法復原的,而且對於同一個明文的加密結果一般不同。

本文出自:http://my.oschina.net/donhui/blog/379925

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.