欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java的java.security.egd源碼解讀

 更新時間:2023年08月22日 09:38:45   作者:codecraft  
這篇文章主要為大家介紹了java的java.security.egd源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

本文主要研究一下java的java.security.egd

SunEntries

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/SunEntries.java

// name of the *System* property, takes precedence over PROP_RNDSOURCE
    private final static String PROP_EGD = "java.security.egd";
    // name of the *Security* property
    private final static String PROP_RNDSOURCE = "securerandom.source";
    final static String URL_DEV_RANDOM = "file:/dev/random";
    final static String URL_DEV_URANDOM = "file:/dev/urandom";
    private static final String seedSource;
    static {
        seedSource = AccessController.doPrivileged(
                new PrivilegedAction<String>() {
            @Override
            public String run() {
                String egdSource = System.getProperty(PROP_EGD, "");
                if (egdSource.length() != 0) {
                    return egdSource;
                }
                egdSource = Security.getProperty(PROP_RNDSOURCE);
                if (egdSource == null) {
                    return "";
                }
                return egdSource;
            }
        });
    }

 這里優(yōu)先讀取java.security.egd,如果沒有設(shè)置則讀取$JAVA_HOME/jre/lib/security/java.security文件中的securerandom.source配置,默認(rèn)值為file:/dev/random

SeedGenerator

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/SeedGenerator.java

// Static initializer to hook in selected or best performing generator
    static {
        String egdSource = SunEntries.getSeedSource();
        /*
         * Try the URL specifying the source (e.g. file:/dev/random)
         *
         * The URLs "file:/dev/random" or "file:/dev/urandom" are used to
         * indicate the SeedGenerator should use OS support, if available.
         *
         * On Windows, this causes the MS CryptoAPI seeder to be used.
         *
         * On Solaris/Linux/MacOS, this is identical to using
         * URLSeedGenerator to read from /dev/[u]random
         */
        if (egdSource.equals(SunEntries.URL_DEV_RANDOM) ||
                egdSource.equals(SunEntries.URL_DEV_URANDOM)) {
            try {
                instance = new NativeSeedGenerator(egdSource);
                if (debug != null) {
                    debug.println(
                        "Using operating system seed generator" + egdSource);
                }
            } catch (IOException e) {
                if (debug != null) {
                    debug.println("Failed to use operating system seed "
                                  + "generator: " + e.toString());
                }
            }
        } else if (egdSource.length() != 0) {
            try {
                instance = new URLSeedGenerator(egdSource);
                if (debug != null) {
                    debug.println("Using URL seed generator reading from "
                                  + egdSource);
                }
            } catch (IOException e) {
                if (debug != null) {
                    debug.println("Failed to create seed generator with "
                                  + egdSource + ": " + e.toString());
                }
            }
        }
        // Fall back to ThreadedSeedGenerator
        if (instance == null) {
            if (debug != null) {
                debug.println("Using default threaded seed generator");
            }
            instance = new ThreadedSeedGenerator();
        }
    }

 如果是file:/dev/randomfile:/dev/urandom則走NativeSeedGenerator,不是則走URLSeedGenerator,為空則走ThreadedSeedGenerator

NativeSeedGenerator

/**
 * Native seed generator for Unix systems. Inherit everything from
 * URLSeedGenerator.
 *
 */
class NativeSeedGenerator extends SeedGenerator.URLSeedGenerator {
    NativeSeedGenerator(String seedFile) throws IOException {
        super(seedFile);
    }
}
NativeSeedGenerator繼承了URLSeedGenerator

SecureRandomSpi

NativePRNG

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/src.zip!/sun/security/provider/NativePRNG.java

public final class NativePRNG extends SecureRandomSpi {
    private static final long serialVersionUID = -6599091113397072932L;
    private static final Debug debug = Debug.getInstance("provider");
    // name of the pure random file (also used for setSeed())
    private static final String NAME_RANDOM = "/dev/random";
    // name of the pseudo random file
    private static final String NAME_URANDOM = "/dev/urandom";
    // which kind of RandomIO object are we creating?
    private enum Variant {
        MIXED, BLOCKING, NONBLOCKING
    }
    // singleton instance or null if not available
    private static final RandomIO INSTANCE = initIO(Variant.MIXED);
    /**
     * Get the System egd source (if defined).  We only allow "file:"
     * URLs for now. If there is a egd value, parse it.
     *
     * @return the URL or null if not available.
     */
    private static URL getEgdUrl() {
        // This will return "" if nothing was set.
        String egdSource = SunEntries.getSeedSource();
        URL egdUrl;
        if (egdSource.length() != 0) {
            if (debug != null) {
                debug.println("NativePRNG egdUrl: " + egdSource);
            }
            try {
                egdUrl = new URL(egdSource);
                if (!egdUrl.getProtocol().equalsIgnoreCase("file")) {
                    return null;
                }
            } catch (MalformedURLException e) {
                return null;
            }
        } else {
            egdUrl = null;
        }
        return egdUrl;
    }
    //......
}

 NativePRNG的getEgdUrl則通過egdSource來構(gòu)建URL

小結(jié)

  • SunEntries優(yōu)先讀取java.security.egd,如果沒有設(shè)置則讀取$JAVA_HOME/jre/lib/security/java.security文件中的securerandom.source配置,默認(rèn)值為file:/dev/random
  • SeedGenerator判斷egdSource如果是file:/dev/randomfile:/dev/urandom則走NativeSeedGenerator,不是則走URLSeedGenerator,為空則走ThreadedSeedGenerator
  • 至于/dev/./urandom這種表示看起來比較困惑,翻譯過來就是是/dev當(dāng)前目錄下的unrandom,其實就是/dev/urandom,之所以有這種傳參主要是早期jdk版本有個bug,沒有給NativeSeedGenerator傳參,所以通過file:/dev/./urandom繞過這個bug

doc

以上就是java的java.security.egd的詳細(xì)內(nèi)容,更多關(guān)于java.security.egd的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 使用Spring Cache和Redis實現(xiàn)查詢數(shù)據(jù)緩存

    使用Spring Cache和Redis實現(xiàn)查詢數(shù)據(jù)緩存

    在現(xiàn)代應(yīng)用程序中,查詢緩存的使用已經(jīng)變得越來越普遍,它不僅能夠顯著提高系統(tǒng)的性能,還能提升用戶體驗,在這篇文章中,我們將探討緩存的基本概念、重要性以及如何使用Spring Cache和Redis實現(xiàn)查詢數(shù)據(jù)緩存,需要的朋友可以參考下
    2024-07-07
  • Java的方法和this關(guān)鍵字如何理解與應(yīng)用

    Java的方法和this關(guān)鍵字如何理解與應(yīng)用

    Java語言中的“方法”(Method)在其他語言當(dāng)中也可能被稱為“函數(shù)”(Function)。對于一些復(fù)雜的代碼邏輯,如果希望重復(fù)使用這些代碼,并且做到“隨時任意使用”,那么就可以將這些代碼放在一個大括號{}當(dāng)中,并且起一個名字。使用代碼的時候,直接找到名字調(diào)用即可
    2021-10-10
  • Elasticsearch term 查詢之精確值搜索功能實現(xiàn)

    Elasticsearch term 查詢之精確值搜索功能實現(xiàn)

    term查詢是Elasticsearch中用于精確值搜索的一種基本方式,通過了解 term 查詢的工作原理和使用方法,你可以更好地利用 Elasticsearch 進行結(jié)構(gòu)化數(shù)據(jù)的搜索和分析,本文將詳細(xì)介紹 term 查詢的工作原理、使用場景以及如何在 Elasticsearch 中應(yīng)用它,感興趣的朋友一起看看吧
    2024-06-06
  • 記一次Feign中實現(xiàn)傳實體Bean的問題

    記一次Feign中實現(xiàn)傳實體Bean的問題

    這篇文章主要介紹了記一次Feign中如何傳實體Bean的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 聊一聊new對象與Spring對bean的初始化的差別

    聊一聊new對象與Spring對bean的初始化的差別

    這篇文章主要介紹了聊一聊new對象與Spring對bean的初始化的差別,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • Java 泛型(Generic)簡介及用法詳解

    Java 泛型(Generic)簡介及用法詳解

    泛型是一種把類型明確的工作推遲到創(chuàng)建對象或者調(diào)用方法的時候才去明確的特殊的類型,參數(shù)化類型,把類型當(dāng)作參數(shù)一樣的傳遞,本文給大家介紹Java 泛型(Generic)概述及使用,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • Java實現(xiàn)拖拽列表項的排序功能

    Java實現(xiàn)拖拽列表項的排序功能

    這篇文章主要介紹了Java實現(xiàn)拖拽列表項的排序功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • Java實現(xiàn)JDBC連接數(shù)據(jù)庫簡單案例

    Java實現(xiàn)JDBC連接數(shù)據(jù)庫簡單案例

    這篇文章主要介紹了Java實現(xiàn)JDBC連接數(shù)據(jù)庫簡單案例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • java判斷某個點是否在所畫多邊形/圓形內(nèi)

    java判斷某個點是否在所畫多邊形/圓形內(nèi)

    這篇文章主要為大家詳細(xì)介紹了java判斷某個點是否在所畫多邊形或圓形內(nèi)的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Feign實現(xiàn)多文件上傳,Open?Feign多文件上傳問題及解決

    Feign實現(xiàn)多文件上傳,Open?Feign多文件上傳問題及解決

    這篇文章主要介紹了Feign實現(xiàn)多文件上傳,Open?Feign多文件上傳問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11

最新評論